CABasicAnimation resets to initial value after animation completes

后端 未结 15 2528
闹比i
闹比i 2020-12-04 05:44

I am rotating a CALayer and trying to stop it at its final position after animation is completed.

But after animation completes it resets to its initial position.

15条回答
  •  Happy的楠姐
    2020-12-04 06:10

    Simply setting fillMode and removedOnCompletion didn't work for me. I solved the problem by setting all of the properties below to the CABasicAnimation object:

    CABasicAnimation* ba = [CABasicAnimation animationWithKeyPath:@"transform"];
    ba.duration = 0.38f;
    ba.fillMode = kCAFillModeForwards;
    ba.removedOnCompletion = NO;
    ba.autoreverses = NO;
    ba.repeatCount = 0;
    ba.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.85f, 0.85f, 1.0f)];
    [myView.layer addAnimation:ba forKey:nil];
    

    This code transforms myView to 85% of its size (3rd dimension unaltered).

提交回复
热议问题