开发者

How to catch touchBegan by other subviews such us UIScrollView

开发者 https://www.devze.com 2022-12-11 06:50 出处:网络
I have a UIScrollView in my view control but my UIScrollView can\'t catch the touchBegan. touchBegan only execute开发者_如何学Python when touching outside of the UIScrollView. How can catch the touchB

I have a UIScrollView in my view control but my UIScrollView can't catch the touchBegan. touchBegan only execute开发者_如何学Python 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号