类似于SO问题ref:为什么UIView:animateWithDuration立即完成?然而,我的代码是使用[UIView beginAnimation]等
实际上是这样的:
[UIView beginAnimation ...];
[UIView setAnimationDelay: 0.0];
[UIView setAnimationDuration: 1.25];
animatedImage.transform = "scale-up transform";
[UIView setAnimationDelay: 1.25]
[UIView setAnimationDuration: 0.50];
animatedImage.transform = "scale-down transform";
[UIView commitAnimation];
图像立即跳转到缩放大小,然后1.25秒后,它很好地动画到"缩放"大小。如果我链接更多的序列,它们都正确工作,除了第一个。
当你把动画放到同一个beginAnimation区域时,它们会同时动画
通过调用[UIView setAnimationDelay: 1.25],你只是覆盖了你之前的[UIView setAnimationDelay: 0.0]。
发生的是UIView被告知同时放大和缩小。我猜既然你让它向上和向下缩放,它就会跳过最后一个动画,但你确实让它向上缩放,所以它会在没有动画的情况下完成。
我建议使用块语法代替,它允许你在动画完成后做一些事情:
[UIView animateWithDuration:1.25
animations:^{animatedImage.transform = "scale-up transform";}
completion:^(BOOL finished)
{
[UIView animateWithDuration:1.25
animations:^{animatedImage.transform = "scale-down transform";}
];
}
];
完成块中的代码(^{code}结构称为"块")是在第一个动画之后发生的。你可以把它链接到你喜欢的动画中。
(BOOL finished)是与块一起传递的参数。它告诉我们动画是否真的完成了。