How can I unscale the scaling of a UIScrollView?

I use UIScrollView scaling to display images in my iPad app. Scaling works fine, with a pinch, making the image smaller or larger if necessary. I also have bouncesZoomit return to the minimum or maximum increase if the user stretches it too much anyway.

Now I would like to know when the pinch ended with the image 10% smaller than the minimum scaling size and, in this case, prevent failures and cause another animation that compresses the image to “close”. This. Thus, it can be kind of “pinch to close” gesture. What I came up with to do this, in its simplest way, is the following:

- (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;
    }
}

This works great, except that at that moment it is already bouncing, so the setup minimumZoomScaledoes nothing. Thus, rebound and compression occur simultaneously, which, as you can imagine, looks rather strange.

, : ? UIScrollViewDelegate, - , , UIScrollView . , :

  • nil –viewForZoomingInScrollView:, 90% - . , , , .
  • bouncesZoom -scrollViewDidZoom: false, 90%, true, 90%. , 90%, , bouncesZoom .
  • -touchesEnded:withEvent. .
  • UIPinchGestureRecognizer UIScrollView. , ( ) UIScrollView, , . , . - , UIScrollView , .

, . - - ?

+5
3

, . , ! , , , , minimumZoomScale, cachedMinZoomScale ivar . , 90% :

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    if (self.zoomScale / cachedMinZoomScale < 0.90) {
        self.minimumZoomScale = self.zoomScale;
    } else {
        self.minimumZoomScale = cachedMinZoomScale;
    }
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    if (self.zoomScale / cachedMinZoomScale < 0.90) {
        [self shrinkImageToNothing];
    }
}

, , -self.minimumZoomScale , 90% , . , , 90% - , -, , .

Simple. !

+2

. (, ViewDidLoad)

scrollView.bouncesZoom = NO;

+7

Try this, [imageScrollview setBounces: NO];

-2
source

All Articles