Create an Implicit Animation
- PDF for offline use
- Sample Code:
- Related SDKs:
Let us know how you feel about this
This recipe shows how to create an implicit animation using Core Animation.
Follow these steps to create the animation:
- Add an image named
sample.pngto the project with a Build Action of Content.
- Add the following Using directives:
using CoreAnimation; using CoreGraphics;
- In a UIViewController subclass, declare a
CALayerclass variable from the CoreAnimation namespace.
ViewDidLoadmethod, 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.
- In the
ViewDidAppearmethod, create a CATransaction and set the properties on the
CALayerfor the animation.
CATransaction.Begin (); CATransaction.AnimationDuration = 2; layer.Position = new CGPoint (100, 400); CATransaction.Commit ();
CATransaction creates an implicit animation that will interpolate a
layer’s properties to the values set between the
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.