Tuesday, June 4, 2013

UIScrollView zoomBouncing example in Objective C (iOS).

UIScrollView zoomBouncing

A Boolean value that indicates that zooming has exceeded the scaling limits specified for the receiver. (read-only)

@property(nonatomic, readonly, getter=isZoomBouncing) BOOL zoomBouncing

Discussion of [UIScrollView zoomBouncing]
The value of this property is YES if the scroll view is zooming back to a minimum or maximum zoom scaling value; otherwise the value is NO .

UIScrollView zoomBouncing example.
- (void)scrollViewDidEndZooming:(UIScrollView *)aScrollView withView:(UIView *)view atScale:(float)scale {
NSLog(@"scrollViewDidEndZooming: scale = %f", scale);
if (fabsf(scale - 1.0) < 1e-5) {
if (scrollView.zoomBouncing)
NSLog(@"scrollViewDidEndZooming, but zoomBouncing is still true!");

// cannot call setPagingMode now because scrollView will bounce after a call to this method, resetting contentOffset to (0, 0)
scrollViewMode = ScrollViewModeAnimatingFullZoomOut;
// however sometimes bouncing will not take place
[self performSelector:@selector(setPagingMode) withObject:nil afterDelay:0.2];

Example of [UIScrollView zoomBouncing].
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    if (self.zoomBouncing && zoomedToScale / self.minimumZoomScale < 0.90) {
        // We've let go and were under 90% of the minimum size.
        self.minimumZoomScale = zoomedToScale;
        [self shrinkImageToNothing];
    } else {
        // How far have we gone?
        zoomedToScale = self.zoomScale;

End of UIScrollView zoomBouncing example article.