1

Pan works fine for me, but pinch with recognizer code like this does not:

- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{
    CGFloat scale = pinchRecognizer.scale;
    self.imageView.transform = CGAffineTransformScale(self.imageView.transform, scale, scale);
    pinchRecognizer.scale = 1.0;
}

What happens is that the image view is continuously resetting the image according to its "mode", whether it's center, aspect fit, etc.

Dogweather
  • 15,512
  • 17
  • 62
  • 81
  • Maybe that helps: http://rogchap.com/2011/06/10/ios-image-manipulation-with-uigesturerecognizer-scale-move-rotate/ – Krumelur Apr 11 '13 at 18:15

1 Answers1

1

I solved my problem: I'm making my first image viewer, and to learn how to pinch and zoom, I naively googled for how to support gestures, which are not enabled by simply adding an image view to a view controller.

Unfortunately, there are many "tutorials" on this, showing how to program with the gesture recognizers, etc. And I spent a few hours going down this route unnecessarily. I kept going because I felt tantalizingly close to getting things working: The pan gesture was flawless and was "just" zoom that was broken.

(Side question: is there some awesome source for current, iOS 6 "best practices"?)

It turns out, this is the wrong path and needlessly complex for basic gesture recognition. All that's needed is to place the image view in a scroll view. 99% of the programming is taken care of. (I was convinced this had to be the case — I couldn't believe that such core functionality wouldn't be provided by cocoa touch.)

Community
  • 1
  • 1
Dogweather
  • 15,512
  • 17
  • 62
  • 81