views:

36

answers:

1

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:@"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.

+1  A: 

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.

Jasarien