成长小计-控制器中有UIScrollView控件时,无法响应触摸事件

来源:互联网 发布:jquery 数组如何清空 编辑:程序博客网 时间:2024/06/08 06:12

分析:为什么含有UIScrollView这个控件时,重写touchesegan方法会没有反应,我们从响应链来分析,所有的事件都是一层层传递下去的,顶层UIResponder中包touchesegan方法,所以事件就是在这里被拦截,无法执行。

解决办法:写一个UIScrollView的分类

#import "UIScrollView+XYTouch.h"@implementation UIScrollView (XYTouch)- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {        [[self nextResponder] touchesBegan:touches withEvent:event];        //重写会走两次//    [super touchesBegan:touches withEvent:event];}
这样就完美解决了,只需要在用到的地方导入即可

0 0
原创粉丝点击