如何使用 UIView animateWithDuration 正确缩放 UIImageView?
我正在缩放 UIImageView,然后使用 UIView animateWithDuration 和 UIViewAnimationOptionAutoreverse 选项恢复它。问题是图像动画在动画结束时有点锯齿(抽搐)。这是我的代码:
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionAutoreverse
animations:^{
myImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);}
completion:^(BOOL finished){if (finished){
myImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);}}];
我知道我错过了一些东西,但不知道从哪里开始:(
更新1:我正在执行嵌套的 6 个动画,其中每个下一个动画在上一个动画之后执行。为此,我使用块动画并执行完整块中的每个下一个动画
:我已尝试使用 UIViewAnimationOptionRepeat 选项,但每个缩放动画后仍然有一些闪光效果。
I'm scaling UIImageView and then reverting it using UIView animateWithDuration with UIViewAnimationOptionAutoreverse option. The problem is the image animation is a little bit jaggy (twitching) at the end of the animation. Here's my code:
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionAutoreverse
animations:^{
myImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);}
completion:^(BOOL finished){if (finished){
myImage.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);}}];
I know that I'm missing something but don't know where to start :(
UPDATE1: I'm performing nested 6 animations where each next animation performs after previous one. For that I'm using block animations and performing each next animation in complete block.
UPDATE2: I have tried with UIViewAnimationOptionRepeat option but there's still some flash effect after each scale animation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不使用
UIViewAnimationOptionRepeat
选项,UIViewAnimationOptionAutoreverse
不会执行任何操作。您编写的动画会将图像缩小到 90%,然后在完成块中恢复到 100%。也许您可以在这个动画之后播放另一个在四分之一秒内缩小到 100% 的动画。像这样的东西:UIViewAnimationOptionAutoreverse
does nothing without also using theUIViewAnimationOptionRepeat
option. Your animation as written will shrink the image to 90%, then snap back to 100% in the completion block. Maybe you can follow this animation with another that scales back to 100% over a quarter second. Something like this:.h 文件解密。
代码中的 .m 文件并尝试。
.h file declerd.
.m file in code and try.