关于UIScrollView响应touchesBegan和touchesEnd
响应 关于 touchesBegan UIScrollView
2023-06-13 09:12:40 时间
ViewController中,常用touch事件关闭编辑事件,收起键盘。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
但是addSubview的UIScorllView并不能直接响应touchesBegan和touchesEnd事件。
因此需要继承UIScrolleView类,并重写方法。
@interface myScrollView : UIScrollView
@end
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
if ( !self.dragging ) {
[[self nextResponder] touchesBegan:touches withEvent:event];
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
if ( !self.dragging ) {
[[self nextResponder] touchesEnded:touches withEvent:event];
}
}
使用重写过的UIScrollView就可以通过传递事件,来响应这两个方法。
这个问题背后反应的是iOS的Responder chain (响应链)。
参考:http://mobile.51cto.com/hot-404894.htm
IOS开发之手势——UIGestureRecognizer 共存
转载于:https://www.cnblogs.com/karl87/p/5105162.html
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164193.html原文链接:https://javaforall.cn
相关文章
- 网络诊断dns服务器未响应,网络诊断提示DNS服务器未响应解决方法
- 【说站】Nginx响应超时报错:upstream timed out (110: Connection timed out) 原因及解决方案
- SpringCloudRPC调用核心原理:RxJava响应式编程框架,聚合操作符
- 【Bug解决思路】Tomcat返回不安全的响应头
- 如何正确理解 RT 并监控 MySQL 的响应时间
- (四)定义响应式数据的第二种方法
- JSP Response.setDateHeader()方法:设置响应头信息
- 360Bug Cloud开源漏洞响应平台
- Redis推动静态页面缓存快速响应(redis静态页面缓存)
- Yac缓存与Redis实现快速应用响应(yac缓存和redis)
- 红色之火零延迟的Redis高可用架构(redis高可用无响应)
- 使用Redis消息系统构建快速响应的交互体验(redis消息系统)
- 为Java应用程序添加退出事件响应
- jQuery的Ajax时无响应数据的解决方法
- tangram框架响应式加载图片方法