iPhone iOS how to add a UILongPressGestureRecognizer and UITapGestureRecognizer to the same control and prevent conflict?

前端 未结 5 595
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 19:25

I\'m building an iPhone app that would let the user rearrange some of the UI elements on the screen.

How can I add a tap gesture recognizer and a long press gesture rec

5条回答
  •  名媛妹妹
    2021-02-01 19:45

    To allow both gestures to work together, implement the following delegate method:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
        return YES;
    }
    

    To make it so that the long press has first priority, do:

    [tapGesture requireGestureRecognizerToFail:longPress];

提交回复
热议问题