2012-09-26 17 views
1

我需要围绕我的一个图像浏览产生辉光效果。为此,我决定使用shadowopacity属性。iOS 5:为什么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

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

anim.autoReverses= YES; 

有大写字母“R”的问题正确的代码:

anim.autoreverses= YES; 

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

+0

我已经在这里添加了这一行,但没有在我的代码中,这是问题: - )...无论如何你是对的。 Upvoted并标明正确。谢谢! –

+0

很高兴我能帮到你。 – stringCode

相关问题