2010-07-03 100 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]]]; 
}