2013-06-17 1 views
3

ce que j'essaie de faire est de simuler une impulsion autour de mon bouton. Je peux obtenir l'effet de lueur pour travailler en changeant les propriétés de la couche du bouton. Cependant, je n'arrive pas à l'animer. Ici, il est ce que je l'ai essayé jusqu'à présent:voir l'animation ne fonctionne pas pour shadowRadius iOS

UIColor *confirmButtonColor = self.btnConfirm.currentTitleColor; 
self.btnConfirm.layer.shadowOffset = CGSizeZero; 

self.btnConfirm.layer.masksToBounds = NO; 
self.btnConfirm.layer.shadowColor = confirmButtonColor.CGColor; 
self.btnConfirm.layer.shadowRadius = 6.0f; 
self.btnConfirm.layer.shadowOpacity = .0f; 
[UIView animateWithDuration:1.2 delay:5 options:UIViewAnimationCurveLinear animations:^{ 
    self.btnConfirm.layer.shadowOpacity = 1.0f; 
}completion:nil]; 

sans être animés apparaissent La lueur; J'ai aussi essayé de mettre tout le code dans l'animation et je n'ai pas changé. Et oui, j'importe Quartz.

Merci

Répondre

7

Je ne comprends pas pourquoi ce que vous avez ne fonctionne pas (peut-être quelqu'un peut nous éclairer) mais cela fonctionne:

UIColor *confirmButtonColor = self.btnConfirm.currentTitleColor; 
self.btnConfirm.layer.shadowOffset = CGSizeZero; 

self.btnConfirm.layer.masksToBounds = NO; 
self.btnConfirm.layer.shadowColor = confirmButtonColor.CGColor; 
self.btnConfirm.layer.shadowRadius = 6.0f; 
self.btnConfirm.layer.shadowOpacity = 1.0f; // Note: You need the final value here 
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; 
animation.fromValue = [NSNumber numberWithFloat:.0]; 
animation.toValue = [NSNumber numberWithFloat:1.0]; 
[self.btnConfirm.layer addAnimation:animation forKey:@"shadowOpacity"]; 
+0

Oui @clafou si je l'utilise CABasicAnimation cela fonctionne. Cependant, si j'utilise [UIVew animationWithDuration ...}, cela ne fonctionne pas – Camus

+3

Alors que 'animationWithDuration ...' de UIView prend en charge un certain nombre de propriétés d'affichage UIKit (qui sont toutes documentées sous Animations dans le document [UIView doc] (http: // developer .apple.com/bibliotheque/ios/ # documentation/UIKit/Reference/UIView_Class/UIView/UIView.html)), il ne gère pas les changements de propriétés CALayer. Vous êtes donc coincé avec Core Animation pour les animations de niveau couche. Vous pouvez toujours obtenir le même délai et la fonction d'accélération, c'est juste un peu plus de code. – Clafou

Questions connexes