4

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

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.

谢谢

4

1 回答 1

8

我不清楚为什么你所拥有的东西不起作用(也许有人可以启发我们)但这有效:

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"];
于 2013-06-17T15:04:36.547 回答