2010-11-13 17 views
1

Dans le passé, quand je voulais faire une belle animation de fondu d'un texte UILabel à un autre, je mandrin dans le texte suivant: Comme vous pouvez dire probablementMeilleure façon de faire des animations UILabel dans Cocoa Touch?

[UIView beginAnimations:@"fade" context:nil]; 
[UIView setAnimationDuration:0.25]; 
myLabel.alpha = 0.0; 
myLabel.text = @"Different string"; 
myLabel.alpha = 1.0; 
[UIView commitAnimations]; 

, l'étiquette ne un fondu de sortie rapide , changez de contenu, puis retombez en arrière.

J'ai vu quelques exemples dans d'autres applications où le texte semble s'évanouir en douceur - sans avoir l'air de disparaître rapidement.

Est-ce juste moi ou y at-il un meilleur moyen d'y parvenir?

Merci. Ricky.

+0

pas pour harceler, mais a fait ma réponse ... répondre à votre question? – griotspeak

Répondre

3

Espérons que cela aide.

-(void)showButton:(UIButton *)button { 
     CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
     opacityAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 
     opacityAnimation.toValue = [NSNumber numberWithFloat:1.0f]; 

     button.hidden = NO; 

     [button.layer addAnimation:opacityAnimation 
          forKey:@"opacity"]; 
    } 

    -(void)hideButton:(UIButton *)button { 

     CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
     opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0f]; 
     opacityAnimation.toValue = [NSNumber numberWithFloat:0.0f]; 
     button.hidden = YES; 

     [button.layer addAnimation:opacityAnimation 
          forKey:@"opacity"]; 
    }