开发者

Layer animation works fine first time, but not on second identical invocation

开发者 https://www.devze.com 2023-01-16 08:56 出处:网络
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 immediatelyand the an开发者_StackOverflow中文版i

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消