UIScrollView无法响应touch事件解决方法
来源:互联网 发布:淘宝 seo 教程 编辑:程序博客网 时间:2024/05/16 02:21
UIScrollView不会响应touch事件,这样就无法在touchesEnd方法中做一些事情了,比如关闭键盘等等。可以写个category解决这个问题
#import "UIScrollView+TouchEvent.h"
@implementation UIScrollView (TouchEvent)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[selfnextResponder]touchesBegan:toucheswithEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[selfnextResponder]touchesMoved:toucheswithEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[selfnextResponder]touchesEnded:toucheswithEvent:event];
[super touchesEnded:touches withEvent:event];
}
@end
UITableView是不会响应touchesBegan:withEvent:之类的UIResponder的方法的。因此,加在其上的所有视图的响应者链就断了。如果在UITableView其上加任何的自身不具备类似UIButton一样有目标动作机制的UIView及其子类控件的时候,这个控件也不会响应touchesBegan:withEvent:方法。即便是设置该控件的userInteractionEnabled为YES也没用。
如此一来,如果想要这些控件具有交互性能怎么办?有一种很直观的方法,给这个控件加上手势识别器。
- (void)addAGesutreRecognizerForYourView
{
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturedDetected:)]; // 手势类型随你喜欢。
tapGesture.delegate = self;
[yourView addGestureRecognizer:panGesture];
}
- (void)tapGesturedDetected:(UITapGestureRecognizer *)recognizer
{
// do something
}
- UIScrollView无法响应touch事件解决方法
- UIScrollView无法响应touch事件的解决办法
- UIScrollView无法响应touch事件的解决办法
- UIScrollView UICollectionView 无法响应touch事件
- UIScrollView无法响应touch事件的解决办法
- 『IOS』UIScrollView无法响应touch事件的解决办法
- UIScrollView不能响应touch事件的解决办法
- 如何让UIScrollView里面的UIImageView响应touch事件
- 关于UIScrollview不能响应touch事件的解决办法
- scrollview/tableview 无法响应touch事件
- UIScrollView touch 触摸事件
- UIScrollView响应touchesBegan事件
- UIScrollView的touch事件特点
- 解决UIScrollView,UIImageView等控件不能响应touch事件的问题
- [IOS]UIScrollView响应UITouch事件
- UIScrollView的事件响应原理
- UIScrollView不能响应UITouch事件
- 递归动画UIView animate 无法响应内部点击事件 touch事件
- 辗转相除
- Tomcat启动时提示端口号冲突
- iOS block传值
- 根据excel模板导出excel
- UI(base)-1
- UIScrollView无法响应touch事件解决方法
- SDUT 2879 Colorful Cupcakes (2014年山东省第五届ACM大学生程序设计竞赛)
- 最小生成树 prim
- Android6.0 wakelock深入分析
- 基因数据处理45之cloud-scale-bwamem安装(compile.pl安装有问题)
- 数据库设计(一对一、一对多、多对多)
- spring 三大基本组件
- 常用的调试器——概述篇
- Linux常用命令总结