Reputation: 203
I'm trying to set up a pinch gesture on the root view in my view hierarchy. This pinch gesture is not recognized if the two touches that make up the pinch are located in two different subviews. In the following diagram my green root view is not recognizing a pinch gesture (denoted by orange touches) because each touch exists in a different blue subview. These blue subviews are siblings in the view hierarchy and children of the green root view.
The pinch gesture is properly recognized if both touches occur within the same subview. The pinch gesture recognizer never changes state, and so never gets a chance to recognize the pinch, when touches occur within different subviews (as verified by subclassing UIPinchGestureRecognizer and logging calls to setState:).
Finally, the subview's and root view all process a number of other gestures including pan and taps. I tried adding a clear overlay to the view hierarchy to capture the pinch, which worked, but that clear overlay view blocks touches and taps that are correctly targeted at the blue subviews.
Is there a way to get the pinch gesture working in situations like in the above diagram, or am I doomed to only being able to recognize the pinch if it happens within one view in the hierarchy?
Upvotes: 1
Views: 314
Reputation: 69
My problem had smth common with yours - UIPinchGestureRecognizer didn't work on superview when both fingers was on 1 subview. It had UIScrollView in it, whose inner pich recognizer was delaing my own.
Also problem could be solved by setting gesture recognizer delegate and setting it's ability to catch touches when another recognizers do so
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;}
but it was not my case (needed them to wait each other because of customer will)
Upvotes: 1