简体   繁体   中英

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. touchBegan only execute when touching outside of the UIScrollView. How can catch the touchBegan when touching UIScrollView?

Thanks.

You must subclass UIScrollView (or an other view) and re-implement the methods you want to catch. Don't forget to call super in you implementation!

In order to subclass UIScrollView, your MyUIScrollView.h file should look similar to this:

#import <UIKit/UIKit.h>


@interface MyUIScrollView : UIScrollView {

}

@end

Then, in your MyUIScrollView.m , you place your touchesBegan method:

- (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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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