Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

view animation not working for shadowRadius iOS

what I am trying to do is to simulate a pulse around my button. I can get the glow effect to work changing the properties of the button's layer. However, I can not get it to be animated. Here it is what I have tried so far:

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];

The glow appear without being animated; I also tried to put all the code inside the animation and didn't change. And yes, I import Quartz.

Thanks

like image 915
Camus Avatar asked Feb 16 '23 05:02

Camus


1 Answers

I'm not clear why what you have isn't working (perhaps someone can enlighten us) but this works:

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"];
like image 147
Clafou Avatar answered Feb 24 '23 12:02

Clafou