0

How to save latest position of animated view?

here is my code, generally my aim is to rotate view about 60 degree in z axis.

    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;

here is how it looks enter image description here

Nininea
  • 2,671
  • 6
  • 31
  • 57
  • Your question is unclear. What do you mean by latest position? Do you want the View to stay where it is when the animation ends? Do you want the **origin** values? – ezcoding May 29 '15 at 08:00
  • exactly , when animation ends – Nininea May 29 '15 at 08:06
  • @ezCoding have edited my question. have you any idea? – Nininea May 29 '15 at 08:08
  • possible duplicate: http://stackoverflow.com/questions/6059054/cabasicanimation-resets-to-initial-value-after-animation-completes – ezcoding May 29 '15 at 08:09
  • @ezCoding you are right , but this solution doesn't work for me. as you see my code includes this lines: rotationAnimation.FillMode = "kCAFillModeForwards"; rotationAnimation.RemovedOnCompletion = false; what was answers there. – Nininea May 29 '15 at 08:11
  • I'm seeing that you are using a **String** while the other answer used a constant to apply the desired behavior. – ezcoding May 29 '15 at 08:12
  • @ezCoding ah great, thanks ^_^ It was my fault . you made my day ^_^ – Nininea May 29 '15 at 08:16
  • @ezCoding add this comment as an answer and I will mark it as correct one – Nininea May 29 '15 at 08:17

2 Answers2

0

simply set:


rotationAnimation.AutoReverses = false;  
scorpiozj
  • 2,687
  • 5
  • 34
  • 60
0

Look at this answer

You are using a String for the fillMode and which doesn't have the same value as the constant needed here. So change your code to:

rotationAnimation.FillMode = CAFillMode.Forwards
Community
  • 1
  • 1
ezcoding
  • 2,974
  • 3
  • 23
  • 32