Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode 6 zoomToRect animated issue

I got a photo gallery app an have an issue getting ready for ios 8. The images are displayed in a UIPageViewController and every page has a view with a custom UIScrollView class. It's just like Apples PhotoScroller Sample (https://developer.apple.com/library/ios/samplecode/PhotoScroller/Introduction/Intro.html)

I added a UITapGestureRecognizer for double tapping. Here's the code i use for zooming:

- (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 / build it on xcode 6 gm the animation for the zoom gets wierd. First the content offset is set to the future location, and then it zooms in. So the images is jumping up or down.

anyone had this issue before or have any ideas?

like image 898
Kevin Flachsmann Avatar asked Sep 12 '14 07:09

Kevin Flachsmann


2 Answers

okay i found a workaround. the problem is the animation calls layoutsubviews before the zooming. 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 anyone could tell me why i have to do that.

EDIT: If someone's still interested, move the code from layoutsubviews toscrollViewDidZoom:(UIScrollView *)scrollView. So there's no need for that weird animation an pinch to zoom also works smoothly.

like image 72
Kevin Flachsmann Avatar answered Nov 15 '22 07:11

Kevin Flachsmann


I found the same bug when zooming with pinch gesture. I solved this by calling layoutSubviews in scrollViewDidScroll delegate method:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self layoutSubviews];
}
like image 27
bartl Avatar answered Nov 15 '22 07:11

bartl