After rotating a CALayer using CABasicAnimation the layer jumps back to it's unrotated position

前端 未结 3 1525
忘掉有多难
忘掉有多难 2020-12-13 02:58

I am trying to create a falling coin. The coin image is a CALayer with 2 CABasicAnimations on it - a falling down and a rotation one. When the falling down animation gets to

3条回答
  •  不知归路
    2020-12-13 03:19

    I was trying to rotate an arrow back and forth, like the Twitter/Facebook "Pull to Refresh" effect.

    The problem is, I was doing the rotation back and forth on the same UIView, so after adding

    rotation.removedOnCompletion = NO;
    rotation.fillMode = kCAFillModeForwards;
    

    The forward animation war working OK but the backwards animation was not working at all.

    So I added the last line suggested by yeahdixon, and in addition set the view's transform to the animation's completed state: (rotation by 180 degrees)

    [myview.layer removeAllAnimations];
    myView.transform = CGAffineTransformMakeRotation(M_PI);
    

    For the 'restore' animation (backwards) I do this on completion:

    myView.transform = CGAffineTransformMakeRotation(0);
    

    ...and it works fine. Somehow it doesn't need the removeAllAnimations call.

提交回复
热议问题