Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView detect pinch zoom end

I'm trying to get notified when UIScrollView is pinch zoomed out beyond its minimum zoom limit and is about to animate back, but I'm finding it very difficult. Is there a way I can do this with delegate methods alone or do I need to override UIScrollView's touch handling?

like image 315
Nick Avatar asked Jan 26 '11 20:01

Nick


2 Answers

Use scrollViewDidZoom: and check if scrollView.zoomBouncing == YES. Then use zoomScale to determine which direction the view is bouncing.

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    if (scrollView.zoomBouncing) {
        if (scrollView.zoomScale == scrollView.maximumZoomScale) {
            NSLog(@"Bouncing back from maximum zoom");
        }
        else
        if (scrollView.zoomScale == scrollView.minimumZoomScale) {
            NSLog(@"Bouncing back from minimum zoom");
        }
    }
}
like image 158
Gary Chapman Avatar answered Oct 14 '22 07:10

Gary Chapman


You can use UIScrollView's scrollViewDidZoom delegate method to detect the moment it's about to animate back. You'll see scrollView.zoomScale drop below scrollView.minimumZoomScale while the view is being pinched. Then, as soon as the user releases their fingers, scrollViewDidZoom will be called once again with scrollView.zoomScale == scrollView.minimumZoomScale, but scrollView.zooming == NO.

Capturing this moment is fine and all, but attempting to do anything to preempt the bounce-back-to-minimumZoomScale animation seems to have really odd side effects for me. :(

like image 2
strawtarget Avatar answered Oct 14 '22 07:10

strawtarget