2010-07-03 226 views
2

我使用UIImageView的animationImages来显示一秒钟内的一些帧。我想展示动画,然后让它停留在最后一帧。在操作系统3.1.3,这工作得很好:在最后一帧停止UIImageView动画

[self setAnimationRepeatCount:1]; 
[self setAnimationDuration:1]; 
[self startAnimating]; 
// auto set the last image in the frame 
[self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"frame-%d_29.png", self.frameSet]]]; 

当动画完成后,它会显示图像。 OS 4没有这样的运气。我已经尝试设置NSTimer并在完成时设置静态帧,但是有时会使用该方法显示闪烁。任何解决方案

回答

1

编辑

甚至比以前更好的解决方案是简单地切换启动顺序并设置:

[self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"frame-%d_29.png", self.frameSet]]]; 
[self startAnimating]; 

周围多一点搞乱后,我发现的NSTimer解决实际如果将延迟设置为29/30秒,即〜0.97,则工作:

- (void)doAnimation 
{ 
    [self setAnimationRepeatCount:1]; 
    [self setAnimationDuration:1]; 
    [self startAnimating]; 
    [NSTimer scheduledTimerWithTimeInterval:0.97f 
            target:self 
            selector:@selector(onTimer:) 
            userInfo:nil 
            repeats:NO]; 
} 

- (void)onTimer:(NSTimer *)theTimer 
{ 
    [self stopAnimating]; 
    [self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"frame-%d_29.png", self.frameSet]]]; 
}