iPhone iOS how to make UIRotationGestureRecognizer and UIPinchGestureRecognizer to work together to scale and rotate a UIView with subviews?

前端 未结 1 1162
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 20:22

I\'m implementing a drag/drop/resize/rotate labels within my app. So far everything is working except for the UIRotationGestureRecognizer gesture. More specifically

1条回答
  •  星月不相逢
    2021-02-14 21:00

    If you want two gestureRecognisers to run in parallel (simultaneously) your view should implement .

    Also, you should make it a delegate of both gestureRecognizers.

    rotationGestureRecognizer.delegate=self;
    pinchGestureRecognizer.delegate=self;
    

    And you also should implement shouldRecognizeSimultaneouslyWithGestureRecognizer: method:

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

    NOTE: if you have more then this two gestureRecognisers in your view you're gonna have to add some identity checking in this method.

    EDIT:

    Just found Ole Begemann's article on this topic: Gesture Recognition on iOS with Attention to Detail

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