簡體   English   中英

iPhone動畫延遲問題

[英]iPhone animation delay problem

我正在嘗試使該動畫延遲60秒,並花費125秒來完成它的動畫周期。 然后無限重復。 問題是延遲僅持續20秒。 您可以指定的延遲時間是否有限制? 或者,也許是一種更好的方式來做我正在嘗試的事情?

這是我的代碼:

- (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];
}

謝謝你的幫助。

您以錯誤的方式使用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:這將啟動圖像視圖的動畫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM