Tuesday, June 4, 2013

UIScrollView zoomScale example in Objective C (iOS).


UIScrollView zoomScale

A floating-point value that specifies the current scale factor applied to the scroll view's content.

@property(nonatomic) float zoomScale

Discussion of [UIScrollView zoomScale]
This value determines how much the content is currently scaled. The default value is 1.0.

UIScrollView zoomScale example.
You should use a different UIScrollViewDelegate method.

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    // Your code here
    float scale = [scrollView zoomScale];
    [self updateAuxViewScale:scale];
}

Example of [UIScrollView zoomScale].
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    //reset zoomScale back to 1 so that contentSize can be modified correctly
    self.scrollView.zoomScale = 1;

    // reset scrolling area equal to size of image
    self.scrollView.contentSize = self.imageView.image.size;

    //reset the image frame to the size of the image
    self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);

    //set the zoomScale to what we actually want
    self.scrollView.zoomScale = [self findZoomScale];
}

UIScrollView zoomScale example.
When you do a block animation like in your code:

[UIView animateWithDuration:4.0
                 animations:^ {
                     self.scrollView.zoomScale = 0.5;
                 }
                 completion:nil];

End of UIScrollView zoomScale example article.