UIScrollView will detect an increase in zoom

I am trying to get a notification when the UIScrollView is zoomed out beyond the minimum zoom limit and is about to revive back, but it's very difficult for me. Is there a way to do this using delegate methods, or do I need to override UIScrollView's touch handling?

+5
source share
4 answers

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

 - (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"); } } } 
+9
source

You can use the UIScrollView delegate scrollViewDidZoom delegate method to determine when it revived back. You will see scrollView.zoomScale below scrollView.minimumZoomScale , while the view is pinched. Then, as soon as the user releases his fingers, scrollViewDidZoom will again be called using scrollView.zoomScale == scrollView.minimumZoomScale , but scrollView.zooming == NO .

Capturing this moment is fine and all, but trying to do something to forestall the bounce-back-to-minimumZoomScale animation seems to have really weird side effects for me. :(

+2
source

I did this with a UIPinchGestureRecognizer .

 -(void)viewDidLoad{ UIPinchGestureRecognizer *gestureRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinched:)] autorelease]; gestureRecognizer.delegate=self; [self.scrollView addGestureRecognizer:gestureRecognizer]; //your code } -(void)pinched:(UIPinchGestureRecognizer*)gestureRecognizer{ if(gestureRecognizer.state==UIGestureRecognizerStateEnded){ //pinch ended NSLog(@"scale: %f",scrollView.zoomScale); } } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *)otherGestureRecognizer{ return YES; } 
0
source

A way to find out when the scroll view has been completely reduced in Swift 4.0:

 func scrollViewDidZoom(_ scrollView: UIScrollView) { if scrollView.zoomScale == CGFloat.init(1.0) { print("zoomed out") } } 
0
source

Source: https://habr.com/ru/post/1337206/


All Articles