简体   繁体   English

如何通过其他子视图(例如UIScrollView)捕获touch

[英]How to catch touchBegan by other subviews such us UIScrollView

I have a UIScrollView in my view control but my UIScrollView can't catch the touchBegan. 我的视图控件中有一个UIScrollView,但我的UIScrollView无法捕获touchBegan。 touchBegan only execute when touching outside of the UIScrollView. touchBegan仅在触摸UIScrollView外部时执行。 How can catch the touchBegan when touching UIScrollView? 触摸UIScrollView时如何捕捉touchBegan?

Thanks. 谢谢。

You must subclass UIScrollView (or an other view) and re-implement the methods you want to catch. 您必须子类化UIScrollView (或其他视图),然后重新实现要捕获的方法。 Don't forget to call super in you implementation! 不要忘记在您的实现中调用super!

In order to subclass UIScrollView, your MyUIScrollView.h file should look similar to this: 为了继承 UIScrollView,您的MyUIScrollView.h文件应类似于以下内容:

#import <UIKit/UIKit.h>


@interface MyUIScrollView : UIScrollView {

}

@end

Then, in your MyUIScrollView.m , you place your touchesBegan method: 然后,在MyUIScrollView.m中 ,放置touchesBegan方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

}

After you do this, anywhere in your code where you now use an UIScrollView , you switch to using a MyUIScrollView . 完成此操作后,在代码中现在使用UIScrollView的任何位置,都将切换为使用MyUIScrollView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM