2015/10/29

Pinch and rotation gesture simultaneously

I wanted to set both UIPinchGestureRecognizer and UIRotationGestureRecognizer to one view. I just made both objects and add ‘addGestureRecognizer:’ to the view. Yes, this worked. I was able to zoom in/out and rotate the view, BUT I had to release my fingers from the screen after one gesture finished. I was not able to zoom in/out and rotate a target simultaneously.

Well, this means I have to write code to find two touched points and calculate from their relative positions…?

No.
I found next method of UIGestureRecognizerDelegate in the reference,
- (BOOL)gestureRecognizer:(UIGestureRecognizer * _Nonnull)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer * _Nonnull)otherGestureRecognizer
I just added this method and made this return YES, and it worked as I expected!
This is not a new method(available in iOS 3.2 and later) at all, but I didn’t know this.

Develop | Comments(1) | Trackback(0)
Comment
Comment is pending approval.
Comment is pending blog author's approval.

管理者のみに表示