查看动画不适用于shadowRadius iOS

时间:2013-06-17 14:42:12

标签: ios animation quartz-graphics shadow

我要做的是模拟按钮周围的脉冲。我可以使用发光效果来改变按钮图层的属性。但是,我无法让它变得生动。 这是我到目前为止所尝试的:

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

没有动画就会出现光晕; 我还尝试将所有代码放在动画中并且没有改变。 是的,我导入Quartz

由于

1 个答案:

答案 0 :(得分:7)

我不清楚你为什么没有工作(也许有人可以启发我们),但这有效:

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