void CreateKeyframeAnimation() { // animate the position PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF(200, 300); CGPath path = new CGPath(); path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position"); animPosition.Path = path; animPosition.Duration = 2; _sublayer.AddAnimation(animPosition, "position"); // animate the layer transform _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) }; /* see bug comment below * animRotate.Values = new NSObject[] { * NSNumber.FromFloat (0f), * NSNumber.FromFloat ((float)Math.PI / 2f), * NSNumber.FromFloat ((float)Math.PI) }; */ //BUG: MonoTouch does not have this class method bound as of MonoTouch Versino 3.1.3 //animRotate.ValueFunction = CAValueFunction.FunctionWithName(CAValueFunction.RotateZ); animRotate.Duration = 2; _sublayer.AddAnimation(animRotate, "transform"); }
void CreateAnimationGroup() { PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF(200, 300); CGPath path = new CGPath(); path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position"); animPosition.Path = path; _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) }; CAAnimationGroup spinningMonkeyGroup = CAAnimationGroup.CreateAnimation(); spinningMonkeyGroup.Duration = 2; spinningMonkeyGroup.Animations = new CAAnimation[] { animPosition, animRotate }; _sublayer.AddAnimation(spinningMonkeyGroup, null); }