I need to produce a glow effect around one of my imageviews. For that, I decided to use shadowopacity property.
Here is my code:
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;
However, animation just stops after running once. No repetition. Can anyone see why?
I just ran your code on iOS 5 simulator, it works. Only problem there was capital "R" in
anim.autoReverses= YES;
Correct code:
anim.autoreverses= YES;
Incase you had correct spelling in your code, then problem might be in where you are adding the animation. As I said I just ran the code on iOS 5 simulator and works like charm. Hope this helped