UIGestureRecognizer for part of a UIView

前端 未结 2 735
说谎
说谎 2021-02-04 13:37

I\'m using UIGestureRecognizer in my iOS application and I\'m having some issues.

I only want the gestures to work in a certain area of the view, so I made a new UIView

2条回答
  •  孤城傲影
    2021-02-04 14:10

    Yo can also do:

    gestureRecognizer.delegate = self
    

    somewhere. generally on viewDidLoad(). then you implement the method:

     func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
            let view = self.getTheViewDontWannaConsider() /* or whateva */
    
            let point = touch.location(in:view)
            if point.y >= 50 /* or whateva calc. you want */ {
               return false
            }
            return true
        }
    

提交回复
热议问题