How to make a superview intercept button touch events?

前端 未结 5 1876
盖世英雄少女心
盖世英雄少女心 2020-11-30 12:17

Say I have this code:

#import 

@interface MyView : UIView
@end
@implementation MyView

- (void)touchesMoved:(NSSet *)touches withEvent:         


        
5条回答
  •  情歌与酒
    2020-11-30 12:18

    May I suggest using this approach instead:

        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                                     initWithTarget:self 
                                                     action:@selector(tapDetected:)];
        tapRecognizer.numberOfTapsRequired = 1;
        tapRecognizer.numberOfTouchesRequired = 1;
    
        [self.view addGestureRecognizer:tapRecognizer];
    

    You can do this from the superview, no need to make custom UI elements.

提交回复
热议问题