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

时间:2015-05-29 07:55:20

标签: ios animation xamarin

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

这是我的代码,一般我的目标是在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;

这是它的样子 enter image description here

2 个答案:

答案 0 :(得分:0)

只需设置:


rotationAnimation.AutoReverses = false;  

答案 1 :(得分:0)

看看这个answer

String使用的是fillMode,其值与此处所需的常量的值不同。 所以将代码更改为:

rotationAnimation.FillMode = CAFillMode.Forwards