IOS CABasicAnimation 在动画结束时将视图保存到最新位置

IOS CABasicAnimation save view to latest position when animation ends

如何保存动画视图的最新位置?

这是我的代码,通常我的目标是将视图在 z 轴上旋转大约 60 度。

    CABasicAnimation rotationAnimation = new CABasicAnimation ();
    rotationAnimation.KeyPath = "transform.rotation.y";
    rotationAnimation.From = new NSNumber (0);
    rotationAnimation.To = new NSNumber (0.7);
    rotationAnimation.Duration = 5;
    rotationAnimation.AutoReverses = false; 
    rotationAnimation.FillMode = "kCAFillModeForwards";
    rotationAnimation.RemovedOnCompletion = false;  
    this.contentViewContainer.Layer.AddAnimation (rotationAnimation, "rotationAnimation");

    this.contentViewContainer.Layer.ContentsGravity = CALayer.GravityResizeAspectFill;
    CATransform3D transform = CATransform3D.Identity;
    nfloat d = (nfloat)(1.0 / 500.0);
    transform.m34 = d;
    this.contentViewContainer.Layer.Transform = transform;

这是它的样子

简单设置:


rotationAnimation.AutoReverses = false;  

看看这个answer

您正在为 fillMode 使用 String,它与此处所需的 常量 的值不同。 因此,将您的代码更改为:

rotationAnimation.FillMode = CAFillMode.Forwards