2010-10-13 248 views
1

我試圖讓這個動畫延遲60秒,並花費125秒來完成它的動畫循環。然後無限重複。問題是延遲只持續20秒。您可以指定的延遲是否有限制?或者,也許更好的方式來做我想做的事情?iPhone動畫延遲問題

這裏是我的代碼:

- (void)firstAnimation {   

NSArray *myImages = [NSArray arrayWithObjects: 
                [UIImage imageNamed:@"f1.png"], 
                [UIImage imageNamed:@"f2.png"], 
                [UIImage imageNamed:@"f3.png"], 
                [UIImage imageNamed:@"f4.png"], 
                nil]; 

UIImageView *myAnimatedView = [UIImageView alloc]; 
[myAnimatedView initWithFrame:CGRectMake(0, 0, 320, 400)]; 
myAnimatedView.animationImages = myImages; 

[UIView setAnimationDelay:60.0]; 
myAnimatedView.animationDuration = 125.0; 

myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 

[myAnimatedView startAnimating]; 

[self.view addSubview:myAnimatedView]; 
[self.view sendSubviewToBack:myAnimatedView]; 

[myAnimatedView release]; 
} 

感謝您的幫助。

回答

3

您正在以錯誤的方式使用setAnimationDelay方法。

setAnimationDelay意在UIViewAnimations塊內視圖像這樣動畫改變動畫的屬性時使用:

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDelay:60]; 
//change an animatable property, such as a frame or alpha property 
[UIView commitAnimations]; 

該代碼將60秒延時的屬性變化的動畫。

如果你想延遲UIImageView動畫的圖像,你需要使用NSTimer

[NSTimer scheduledTimerWithTimeInterval:60 
           target:self selector:@selector(startAnimations:) 
           userInfo:nil 
           repeats:NO]; 

然後定義startAnimations:選擇,就像這樣:

- (void)startAnimations:(NSTimer *)timer 
{ 
    [myAnimatedView startAnimating]; 
} 

這樣一來,60秒後,計時器會觸發該方法startAnimations:將開始您的圖像視圖動畫。