Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

id title brief sdk
Create an Implicit Animation
This recipe shows how to create an implicit animation using Core Animation.


Follow these steps to create the animation:

  • Add an image named sample.png to the project with a Build Action of Content.
  • Add the following Using directives:
using CoreAnimation;
using CoreGraphics;
  • In a UIViewController subclass, declare a CALayer class variable from the CoreAnimation namespace.
CALayer layer;
  • In ViewDidLoad method, create the layer and set its content to be the image.
layer = new CALayer ();
layer.Bounds = new CGRect (0, 0, 50, 50);
layer.Position = new CGPoint (100, 100);
layer.Contents = UIImage.FromFile ("sample.png").CGImage;
layer.ContentsGravity = CALayer.GravityResizeAspectFill;
  • Add the layer as a sublayer of the view’s layer.
View.Layer.AddSublayer (layer);
  • In the ViewDidAppear method, create a CATransaction and set the properties on the CALayer for the animation.
CATransaction.Begin ();
CATransaction.AnimationDuration = 2;
layer.Position = new CGPoint (100, 400);
CATransaction.Commit ();

Additional Information

The CATransaction creates an implicit animation that will interpolate a layer’s properties to the values set between the CATransaction.Begin() and CATransaction.Commit() calls. Any properties set on the CATransaction, such as the AnimationDuration in this example, will be used internally to control how the layer’s properties are interpolated over time.