It's funny you should post this now admanamal after I just found a lecture on scroll view.
I was under the impression that the only way to zoom, was to drag in a pinch gesture recogniser object in storyboard, onto my UIImageView and connect some code to it.
However, I've learned that there is no need to add gesture recognisers at all, which is counter intuitive! The iPhone will recognise a pinch gesture within scroll view!
I simply set my image view frame and scroll view content size ilke this
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = _currentContent.Image1;
self.scrollView.contentSize = self.imageView.image.size;
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
}
and then I adjusted the min and max zoom scale in storyboard, and it works.
However, now I have a different problem, that is too related to this thread to be in a new thread.
When the image view presents itself, the content size of the scroll view dominates the whole screen and the image maintains its aspect but is partially off screen. Of course, I could pinch to get the whole image on screen but
1) I want the whole image on screen when the view controller loads
2) I want the image in the centre of the view and not at the upper left corner
3) I don't want the background white
I only know how to take the following action
1)?
2)?
3)set scrollview background to black in storyboard inspector
----------
I assume that recognizer.view is not the same thing as self.scrollView. Setting the min/max zoom on the scroll view only affects how much you can zoom via the scroll view, which is not what you are doing.
You are telling recognizer.view exactly how much to zoom every time you set its transform scale to recognizer.transform. Why not just examine recognizer.scale before doing the transform to make sure that it is within your desired range?
out of interest, how would you modify the following to incorporate the examination of recogniser.scale?
Code:
- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1.0;
self.scrollView.maximumZoomScale = 2.0;
self.scrollView.minimumZoomScale = 0.5;
}