2010-10-13 15 views
1

J'essaye de retarder cette animation de 60 secondes et de prendre 125 secondes pour compléter son cycle d'animation. alors répétez infiniment. le problème est que le retard ne dure que 20 secondes. Y a-t-il une limite au délai que vous pouvez spécifier? ou, peut-être une meilleure façon de faire ce que je tente?Problème de délai d'animation de l'iPhone

voici mon 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]; 
} 

Merci pour toute aide.

Répondre

3

Vous utilisez la méthode setAnimationDelay dans le mauvais sens.

setAnimationDelay est destiné à être utilisé lors de l'animation des modifications aux propriétés animables sur les vues dans un bloc UIViewAnimations comme ceci:

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

Ce code retarder l'animation d'un changement de propriété de 60 secondes.

Si vous souhaitez retarder un UIImageView pour animer ses images, vous devez utiliser un NSTimer.

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

Réglez ensuite le sélecteur startAnimations:, comme ceci:

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

De cette façon, au bout de 60 secondes, la minuterie se déclenche la méthode startAnimations: qui commencera votre point de vue de l'image animant.