How to animate zoomScale on UIScrollView

I need to set zoomScale to 1 in a UIScrollView, but I need it to be animated. I thought I could use CABasicAnimation for this, but NSValue does not seem to have a valueForFloat or valueForNSNumber value, so I'm not sure what to use for animation. Is there a better way to do this?

EDIT: what do I need to add for this?

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"zoomScale"]; animation.duration = 2.3; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; animation.fromValue = [NSNumber numberWithFloat:myScrollview.zoomScale]; animation.toValue = [NSNumber numberWithFloat:1.0]; [myScrollview.layer addAnimation:animation forKey:@"zoomScale"]; 
+4
source share
1 answer

You do not need to resort to CAAnimation for this simple thing, just use -[UIScrollView setZoomScale:animated:] , passing YES as the second parameter.

In any case, if you want to change any aspect of the animation, you can use the “UIView animation” instead, since zoomScale not a directly animated CAAnimation property.

Have you tried something like the following?

 [UIView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ [myScrollView setZoomScale:1.0f animated:NO]; } completion:nil]; 
+11
source

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


All Articles