iPhone动画延迟问题

时间:2010-10-13 07:18:45

标签: iphone animation uiimageview delay

我试图让这个动画延迟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];
}

感谢您的帮助。

1 个答案:

答案 0 :(得分: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:,这将开始您的图像视图动画。

相关问题