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
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"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With