How to cancel UIGestureRecognizer if subview's button pressed

后端 未结 4 607
说谎
说谎 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:54

    Swift 3

    Set UITapGestureRecognizer

    let tap = UITapGestureRecognizer(target: self, action: #selector(Class.didTap))
    tap.delegate = self
    

    UITapGestureRecognizer delegate method:

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return touch.view != buttonThatShouldCancelTapGesture
    }
    

提交回复
热议问题