0
votes

I have a UIScrollView (self.zoomScrollView) with another UIView (self.pageView) in it. I'm animating the zoomScale and contentOffset using

CGPoint p1 = [tap locationInView:self.pageView];
CGPoint p2 = CGPointMake(p1.x * 3, p1.y * 3);
CGPoint d  = CGPointMake(p2.x - p1.x, p2.y - p1.y);
[UIView animateWithDuration:0.2
                      delay:0
                    options:UIViewAnimationOptionBeginFromCurrentState
                 animations:^{
                     [self zoomScrollView].zoomScale = 3;
                     [self.zoomScrollView setContentOffset:d animated:NO];
                 }
                 completion:^(BOOL finished) {
                 }];

The first time this animation runs the contentOffset is set to its final value immediately and then the zoomScale is animated up to meet it. Every other time after that this animation works perfectly. Any ideas on why it doesn't work the first time?

1

1 Answers

0
votes

The zoomScale and contentOffset properties are not animatable, so changing them inside a UView animation block does nothing. To animate contentOffset, just pass YES to setContentOffset:animated: without using an animation block. Likewise for zoomScale (check the docs).

Animatable properties: https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

UIScrollView: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html#//apple_ref/occ/instm/UIScrollView/setZoomScale:animated: