gpt4 book ai didi

ios - 如何在 UIScrollView 上设置 zoomScale 动画

转载 作者:可可西里 更新时间:2023-11-01 03:38:45 26 4
gpt4 key购买 nike

我需要在 UIScrollView 上将 zoomScale 设置回 1,但我需要它是动画的。我以为我可以为此使用 CABasicAnimation,但 NSValue 似乎没有“valueForFloat”或“valueForNSNumber”,所以我不确定将什么用于 CABasicAnimation 的 animation.fromValue 和 animation.toValue。有没有更好的方法来解决这个问题?

编辑:我需要添加什么才能让它工作?

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"];

最佳答案

你不需要为了这个简单的事情求助于 CAAnimation,只需使用 -[UIScrollView setZoomScale:animated:] 传递 YES作为第二个参数。

无论如何,如果您想修改动画的某些方面,您可以改用“UIView 动画”,因为 zoomScale 不是直接由 CAAnimation 设置动画的属性.

您是否尝试过类似下面的操作?

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

关于ios - 如何在 UIScrollView 上设置 zoomScale 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17053757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com