2010-10-13 186 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:将开始您的图像视图动画。