如何在同一个 UIImageView 上连续执行多个动画
我想做两个动画,一个接一个:
[UIView beginAnimations:@"growImage" context:nil];
[UIView setAnimationDuration:0.2f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
image6.transform = CGAffineTransformMakeScale(0.9, 0.9);
[UIView commitAnimations];
[UIView beginAnimations:@"shrinkImage" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
image6.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView commitAnimations];
我知道我可以
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
通过设置 a 来
[UIView setAnimationDidStopSelector:@selector(shrinkImage)];
执行第二个动画但是有没有一种方法可以让我传入值(在本例中是一个名为 image6 的 UIIMageView),所以第二个动画与第一个动画发生在同一个对象上?
谢谢!
I'd like to do two animations, one after the other:
[UIView beginAnimations:@"growImage" context:nil];
[UIView setAnimationDuration:0.2f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
image6.transform = CGAffineTransformMakeScale(0.9, 0.9);
[UIView commitAnimations];
[UIView beginAnimations:@"shrinkImage" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
image6.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView commitAnimations];
I know that I can do the second animation in
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
or by setting a
[UIView setAnimationDidStopSelector:@selector(shrinkImage)];
But is there a way that I can pass in the value (in this case a UIIMageView named image6) so that the second animation occurs on the same object as the first one?
THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想使用基于选择器的方法,您在
setAnimationDidStopSelector
中指定的选择器将传递您在beginAnimations:context 中指定的
context
参数:调用。因此,如果您将 beginAnimations 调用更改为:
那么
image6
将作为上下文参数传递给您的选择器。一种更简单的方法是使用块来完成同样的事情:
If you want to use the selector-based approach, the selector that you specify in the
setAnimationDidStopSelector
gets passed acontext
parameter that you specify in yourbeginAnimations:context:
call.So, if you change your beginAnimations call to:
then
image6
will get passed as the context parameter to your selector.An easier way would be to use blocks to accomplish the same thing:
这是我的代码中的一个示例。但你明白了。您需要使用
CGAffineTransformConcat
将多个动画拼接在一起。你可以这样做 -iOS4有单块动画 你可以使用它来代替两块动画。苹果文档指出,单块动画更流畅,而且很容易将多个动画一个接一个地拼接起来......
更新:经过更仔细的思考,你可以这样做 -
正如你所看到的,之后动画完成后,您可以开始另一个动画,也可以进行清理。这个基于块的动画用于将动画链接在一起......
This is an example from my code. But you get the idea. You need to use
CGAffineTransformConcat
to stitch multiple animation together. You can do this-iOS4 has Single block animation you could use that instead of Two Block animation. Apple documentation states that Single Block animation is more smooth, plus its easy to stitch multiple animations one after the other...
UPDATE: After thinking more carefully, you could do this -
As you can see, after the animation completes, you can start another animation or you can clean up. This block based animation, is used to chain animations together...