UIView animations with autoreverse

前端 未结 3 1626
梦谈多话
梦谈多话 2020-12-12 18:44

I have a problem with the setting UIViewAnimationOptionAutoReverse. Here is my code.

CALayer *aniLayer = act.viewToChange.layer;
[UIView animate         


        
3条回答
  •  醉梦人生
    2020-12-12 19:40

    There is a repeatCount property on CAMediaTiming. I think you have to create an explicit CAAnimation object, and configure it properly. The repeatCount for grow and ungrow would be 2, but you can test this.

    Something a long the lines of this. You would need two CAAnimation objects though, one for the frame and one for the rotation.

    CABasicAnimation *theAnimation;
    
    theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    theAnimation.duration=3.0;
    theAnimation.repeatCount=1;
    theAnimation.autoreverses=YES;
    theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
    theAnimation.toValue=[NSNumber numberWithFloat:degreesToRadians(34)];
    [theLayer addAnimation:theAnimation forKey:@"animateRotation"];
    

    AFAIK there is no way to avoid programming two animation objects.

提交回复
热议问题