How to cancel UIGestureRecognizer if subview's button pressed

后端 未结 4 603
说谎
说谎 2021-02-04 03:27

I am struggling to get the behaviour I would like from the gesture recognisers, specifically cancelling certain gestures if others have fired.

I have a scrollView set to

4条回答
  •  醉梦人生
    2021-02-04 03:40

    Apple documentation shows the answer:

    - (void)viewDidLoad {
          [super viewDidLoad];
          // Add the delegate to the tap gesture recognizer
          self.tapGestureRecognizer.delegate = self;
    }
    
    // Implement the UIGestureRecognizerDelegate method
    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:    (UITouch *)touch {
          // Determine if the touch is inside the custom subview
         if ([touch view] == self.customSubview){
             // If it is, prevent all of the delegate's gesture recognizers
             // from receiving the touch
            return NO;
         }
         return YES;
    }
    

    Of course in this case customSubview would be subview on the page that has buttons in it (or even the buttons on it)

提交回复
热议问题