本文主要是介绍UIScrollView响应touchesBegan事件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用过UIScrollView的都会发现UIScrollView不会响应touch事件,这样就无法在touchesEnd方法中做一些事情了,比如关闭键盘等等。其实写个category就可以解决这个问题了,直接上代码:
@implementation UIScrollView (UITouchEvent)
- (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
这篇关于UIScrollView响应touchesBegan事件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!