I have an animation that works perfectly on the first invocation. But if I want to animate the very same layer again, using the same code, it completes immediately and the an开发者_StackOverflow中文版imationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag is invoked on the delegate with the flag value NO.
Here is the code that adds the animation:
imageView.hidden = NO;
CAKeyframeAnimation* animationOpacity =
[CAKeyframeAnimation animationWithKeyPath:@"opacity"];
...
animationOpacity.duration = 2.0;
animationOpacity.removedOnCompletion = YES;
animationOpacity.delegate = self;
[imageView.layer addAnimation:animationOpacity forKey:@"someKey"];
and this is the delegate action:
-(void) animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
imageView.hidden = YES;
}
BTW, Initially the imageView is visible in the XIB.
Turns out to be a combination of setting view.hidden = YES in the callback and calling the animation code from the parent's viewWillApear. Once I moved the animation code call into parent's viewDidApear instead, things started behaving as expected.
Are you adding the animation again before calling it a second time? If you aren't then you should set removedOnCompletion = NO
animationOpacity.removedOnCompletion = NO;
加载中,请稍侯......
精彩评论