0

我希望在动画停止播放UILabel的确切时刻更新 a 。UIImageView

我在这方面的尝试是使用 -

[self performSelector:@selector(updateLabels) withObject:nil afterDelay:imageView.animationDuration];

updateLabels更新标签的方法在哪里。

这不适用于前几个动画。但是,它在前 3 或 4 次播放后确实有效。

imageNamed用来填充NSArray保存动画图像的那个。根据我的研究,我注意到imageNamed缓存对象。所以我假设前 3 或 4 次运行的滞后是由于缓存的滞后。

有没有办法克服这个?(最好不要改变 using imageNamed,正如我所说的,它在前 3 或 4 个之后的所有其他动画周期上都可以正常工作)。

4

2 回答 2

0

你试过这个吗:(不是更好的实现,但是)//作为例子

在 h.file 中:

UIImageView *im;

im .m - 文件:

 -(void) viewDidLoad
 {
    [super viewDidLoad];

    im = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
   UIImage *firstIm = [UIImage imageNamed:@"foo.png"];  // example pictures
   UIImage *secondIm = [UIImage imageNamed:@"bar.png"];
   im.animationImages = [NSArray arrayWithObject:firstIm, secondIm, nil];
   im.animationDuration = 1.0;
   im.animationRepeatCount = 4;
   [im startAnimating];
   [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabels) userInfo:nil repeats:YES];

}

-(void) updateLabels
{
   if (![im isAnimating]])
   {
      //Update your label
   }
}

它使用 -imageNamed 图片,但在这种情况下,不能更好地检查结束动画。无论如何,它可能对你有帮助。

于 2012-08-21T13:39:37.703 回答
0

添加animationDidStop:在动画停止时执行操作的方法。

  - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished 
 {
    //Update your label
 }

注意不要忘记添加setDelegateselfuiimageview.animation

于 2012-08-21T12:02:24.103 回答