iOS 5:为什么没有shadowopacity重复动画工作?

时间:2012-09-26 13:02:19

标签: ios ios5 calayer shadow cabasicanimation

我需要在我的一个图像视图周围产生一个发光效果。为此,我决定使用shadowopacity属性。

这是我的代码:

imageViewForAnimation.layer.position = viewOrigin;
imageViewForAnimation.layer.shadowColor = [[UIColor yellowColor] CGColor];
imageViewForAnimation.layer.shadowOffset = CGSizeMake(0.0, 0.0);
imageViewForAnimation.layer.shadowRadius = 15.0;
imageViewForAnimation.layer.shadowOpacity = 0.3;
imageViewForAnimation.layer.masksToBounds = NO;
// Set up glow effect
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
anim.fromValue = [NSNumber numberWithFloat:0.0f];
anim.toValue = [NSNumber numberWithFloat:1.0f];
anim.duration = 3.0;
anim.repeatCount = HUGE_VALF;
anim.autoReverses = YES;
[imageViewForAnimation.layer addAnimation:anim forKey:@"shadowOpacity"];

imageViewForAnimation.layer.shadowPath = [UIBezierPath bezierPathWithRect:imageViewForAnimation.bounds].CGPath;

imageViewForAnimation.layer.shadowOpacity = 1.0f;   

但是,动画只在运行一次后停止。没有重复。 谁能明白为什么?

1 个答案:

答案 0 :(得分:1)

我只是在iOS 5模拟器上运行你的代码,它的工作原理。

中唯一存在资本“R”的问题
 anim.autoReverses= YES; 

正确的代码:

 anim.autoreverses= YES;

如果您的代码中拼写错误,那么问题可能出在您添加动画的位置。正如我所说,我只是在iOS 5模拟器上运行代码并且像魅力一样工作。 希望这有帮助