scrollview/tableview 无法响应touch事件
2015-12-18 17:09
417 查看
scrollview 及其子视图无法响应touch事件
办法一:给view添加点击事件
办法二:创建scrollview的分类,重写touch方法
办法一:给view添加点击事件
- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)]; //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。 tapGestureRecognizer.cancelsTouchesInView = NO; //将触摸事件添加到当前view [self.view addGestureRecognizer:tapGestureRecognizer]; } -(void)keyboardHide:(UITapGestureRecognizer*)tap{ [textFiled resignFirstResponder]; }
办法二:创建scrollview的分类,重写touch方法
@implementation UIScrollView (Touch) - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touch begin"); if(!self.dragging) { [[self nextResponder] touchesBegan:touches withEvent:event]; } [super touchesBegan:touches withEvent:event]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(!self.dragging) { [[self nextResponder] touchesMoved:touches withEvent:event]; } [super touchesMoved:touches withEvent:event]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if(!self.dragging) { [[self nextResponder] touchesEnded:touches withEvent:event]; } [super touchesEnded:touches withEvent:event]; } @end
相关文章推荐
- PHP(一)简介
- 修改host文件
- tuxedo tpcall 返回6 的问题
- 易学02
- C#获取Honeywell voyager 1400g扫码后的数据
- Jetty and Tomcat handle Json bug eval() method
- 元素绘制顺序
- Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)
- 工作遇到的问题备忘
- Uiautomator——API详解
- 修改在VS2010环境下建立的C++项目名称
- django-uuslug: 方便的将中文转化成拼音 slug 的工具
- 块级元素和内联元素的区别(HTML)
- 精心收集的Hadoop学习资料(持续更新)
- Android实战 - 音心播放器 (MusicListActivity - 分类信息界面实现)
- hdu1398 Square Coins (完全背包)
- Linux Power Managment详解
- Linux下ORACLE使用RMAN备份指定数据库
- Hibernate多对多映射关系中自定义排序
- web.xml配置详解