在开发中遇到了这样一个问题:为什么我写的touchesBegan方法没有执行呢?怎么解决呢?
我查找了一下原因:UI Scroll View拦截了UI View的事件。解决办法就是让事件传递过去。
具体解决方案:加一个UIScrollView的category。使每个用到UIScrollView的地方只要导入这个category就可以直接响应相关的touch事件了。
#import "UIScrollView+UITouch.h"
@implementation UIScrollView (UITouch)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}
@end
- 如果是事件响应问题,都可以参照此方法尝试。