开发者

iPhone animation delay problem

I'm trying to get this animation to delay for 60 seconds and take 125 seconds to complete it's animation cycle. then repeat infinitely. the problem is that the delay only lasts 20 seconds. Is there a limit on the delay you can specify? or, perhaps a better way to do what I'm attempting?

here's my code:

- (void)firstAnimation {        

NSArray *myImages = [NSArray arrayWithObjects:
                                                     [UIImage imageNamed:@开发者_StackOverflow"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];
}

thanks for any help.


You're using the setAnimationDelay method in the wrong way.

setAnimationDelay is intended to be used when animating changes to animatable properties on views within a UIViewAnimations block like so:

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

That code will delay the animation of a property change by 60 seconds.

If you want to delay a UIImageView from animating its images you'll need to use an NSTimer.

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

Then define the startAnimations: selector, like so:

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

That way, after 60 seconds, the timer will fire the method startAnimations: which will start your image view animating.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜