Xcode 6 zoomToRect animated issue

I have a photo gallery application, you have a problem preparing for ios 8. Images are displayed in the UIPageViewController and each page has a view with a custom UIScrollView class. This is exactly the same as the Apples PhotoScroller sample ( https://developer.apple.com/library/ios/samplecode/PhotoScroller/Introduction/Intro.html )

I added UITapGestureRecognizer for double tap. Here is the code I use to scale:

- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer { if (self.minimumZoomScale == self.maximumZoomScale) return; if (self.zoomScale == self.minimumZoomScale) didDoubleTap = NO; CGPoint pointInView = [recognizer locationInView:_zoomView]; CGFloat newZoomScale; if (!didDoubleTap && self.zoomScale <= self.minimumZoomScale) { newZoomScale = self.zoomScale * 2.5f; newZoomScale = MIN(newZoomScale, self.maximumZoomScale); didDoubleTap = YES; } else { newZoomScale = self.minimumZoomScale; didDoubleTap = NO; } CGSize scrollViewSize = self.bounds.size; CGFloat w = scrollViewSize.width / newZoomScale; CGFloat h = scrollViewSize.height / newZoomScale; CGFloat x = pointInView.x - (w / 2.0f); CGFloat y = pointInView.y - (h / 2.0f); CGRect rectToZoomTo = CGRectMake(x, y, w, h); [self zoomToRect:rectToZoomTo animated:YES]; } 

This works when I run it on xcode 5.1 perfectly, like in any other photo apps. But when I run / create it on xcode 6 gm, the animation for enlargement becomes tougher. First, the content offset is set to a future location, and then it increases. Thus, images jump up or down.

Has anyone had this problem before or had any ideas?

+6
source share
2 answers

OK, I found a workaround. the problem is with the animated calls to layoutsubviews before scaling. so now i do my own animation

 [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^ { inTransition = YES; [self zoomToRect:rectToZoomTo animated:NO]; inTransition = NO; [self layoutSubviews]; } completion:nil]; 

but it would be nice if someone could tell me why I should do this.

EDIT: If anyone else is interested, move the code from layoutsubviews to scrollViewDidZoom:(UIScrollView *)scrollView . Thus, there is no need for this strange animation, and the pinch for enlargement also works smoothly.

+8
source

I found the same error when scaling with a hard pinch. I solved this by calling layoutSubviews in the delegate method scrollViewDidScroll:

 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { [self layoutSubviews]; } 
+4
source

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


All Articles