【问题标题】:Checking When animation stopped检查动画何时停止
【发布时间】:2012-05-03 15:47:16
【问题描述】:

我正在制作一个简单的 UIImageView 动画。基本上我得到了一堆 0-9 的图像编号,我正在使用这段代码对它们进行动画处理。

myAnimation.animationImages = myArray;
myAnimation.animationDuration = 0.7;
myAnimation.animationRepeatCount = 12;
[myAnimation startAnimating];

这里 myArray 是一个 uiimages 数组,即 0.png、1.png 等。

一切都很好,它的动画也很好。我需要知道的是我什么时候知道动画何时停止?我可以使用 NSTimer 但为此我需要一个秒表来检查动画何时开始和停止。有没有更好的方法,这意味着我可以找出 UIImageView 何时停止动画?

我看了这个帖子作为参考。

UIImageView startAnimating: How do you get it to stop on the last image in the series?

【问题讨论】:

  • 看来你正在做一个 UIImageView 动画而不是你所说的 UIView 动画。所以你得到了你想要的错误答案。你应该解决这个问题。
  • Correct 抱歉我的问题中的错字。是的,我正在动画 UIImageView 而不是 UIView。任何人都可以更正我帖子中的编辑 - 将 UIView 更改为 UIImageView。我不能再编辑问题了。谢谢

标签: objective-c ios animation uiimageview


【解决方案1】:

使用animationDidStopSelector。这将在动画完成时触发:

[UIView setAnimationDidStopSelector:@selector(someMethod:finished:context:)];

然后实现选择器:

- (void)someMethod:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {

}

【讨论】:

  • en....还要加上我经常忘记的[UIView setAnimationDelegate:self]哈~
  • 嗨乔尔,感谢您的回答,但我如何判断它需要检查哪个 UIImageview 以查看它是否停止动画?我希望我可以修改上面的问题并将 UIView 更改为 UIImageView。
【解决方案2】:

是的,有比使用 NSTimers 更好的方法。如果您使用的是 iOS 4 或更高版本,最好开始使用块动画。试试这个

 [UIView animateWithDuration:(your duration) delay:(your delay) options:UIViewAnimationCurveEaseInOut animations:^{

        // here you write the animations you want


    } completion:^(BOOL finished) {
        //anything that should happen after the animations are over


    }];

编辑: 哎呀,我想我读错了你的问题。在 UIImageView 动画的情况下,我想不出比使用 NSTimers 或预定事件更好的方法

【讨论】:

  • 抱歉,我的问题有误。我想问如何检查 UIImageView 何时停止动画。
【解决方案3】:

你也可以试试这个:

[self performSelector:@selector(animationDone) withObject:nil afterDelay:2.0];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多