分析:为什么含有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];
}
这样就完美解决了,只需要在用到的地方导入即可
本文分析了UIScrollView中重写touchesBegan方法导致无响应的问题,并提供了解决方案:通过为UIScrollView创建一个分类并重新实现touchesBegan方法,允许事件传递给下一个响应者。
6731

被折叠的 条评论
为什么被折叠?



