UIImageView animation with stop on final frame
I'm using UIImageView's animationImages to show some frames over a second. I want to show the animation then have it rest on the final frame. In OS 3.1.3, this worked fine for that:
[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开发者_运维问答]]];
When the animation was done it would display the image. No such luck with OS 4. I've tried setting an NSTimer and setting the static frame when that finishes, but there's a noticable flicker sometimes with that method. Any solution?
Edit
Even better than the previous solution is simply to switch the order of the start and set:
[self setImage:[UIImage imageNamed:[NSString stringWithFormat:@"frame-%d_29.png", self.frameSet]]];
[self startAnimating];
After messing around a bit more, I found that the NSTimer solution actually works if you set the delay to 29/30ths of a second, i.e. ~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]]];
}
精彩评论