The first thing to try is making sure the recognizers are working "simultaneously". In your delegate, you want to define the following:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return (gestureRecognizer.view == otherGestureRecognizer.view);
}
In my experience, that's enough to give an adequately smooth experience. However, if it's not, then what I'd do is to only update your transform from one of the recognizers, storing the state from the other in a property. Let's say that you've declared a CGFloat
property called cachedScale, which you set to 1.0 in your initializer. Then in your pinch and pan handlers, you'd do the following:
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
self.cachedScale *= recognizer.scale;
}
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer
{
CGAffineTransform transform = CGAffineTransformMakeScale(self.cachedScale, self.cachedScale);
self.cachedScale = 1.0;
CGPoint translation = [recognizer translationInView:recognizer.view.superview];
CGAffineTransformTranslate(transform, translation.x, translation.y);
// do something with your transform
}
If you're just trying to drag a view around, you may have more luck changing the view's center rather than applying a translation to its transform.