ScrollView gesture recognizer eating all touch events

前端 未结 9 715
北恋
北恋 2020-11-27 03:45

I have a UIScrollView to which I added a single tap gesture recognizer to show/hide some UI overlay using:

UITapGestureRecognizer *singleTap = [         


        
相关标签:
9条回答
  • 2020-11-27 04:08

    This should solve your problem.
    Detect touch event on UIScrollView AND on UIView's components [which is placed inside UIScrollView]
    The idea is to tell the gesture recognizer to not swallow up the touch events. To do this you need to set singleTap's cancelsTouchesInView property to NO, which is YES by default.

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    singleTap.cancelsTouchesInView = NO;
    [scrollView addGestureRecognizer:singleTap]; 
    
    0 讨论(0)
  • 2020-11-27 04:08

    Swift 3.0

     let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
     singleTap.cancelsTouchesInView = false
     singleTap.numberOfTapsRequired = 1
     scrollView.addGestureRecognizer(singleTap)
    

    And the selector method be like.

    @objc func handleTap(_ recognizer: UITapGestureRecognizer) {
      // Perform operation
    }
    
    0 讨论(0)
  • 2020-11-27 04:12

    This worked for me in Swift 3 / Xcode 8

    self.scrollView.touchesShouldCancel(in: ** the view you want the touches in **)
    self.scrollView.canCancelContentTouches = false
    

    Good luck!

    0 讨论(0)
提交回复
热议问题