MonoMac.CoreAnimation.CALayer Class
Layers encapsulate position, size and transformation components of a layer as well as implement the CAMediaTiming methods.

See Also: CALayer Members

Syntax

[MonoMac.Foundation.Register("CALayer", true)]
public class CALayer : MonoMac.Foundation.NSObject

Remarks

When you want to use one of the CALayer subclasses as your UIView's backing layer, you need to add the following code snippet to your class:

C# Example

class MyView : UIView {
    //
    // This instructs the runtime that whenever a MyView is created
    // that it should instantiate a CATiledLayer and assign that to the
    // UIView.Layer property
    //
    [Export ("layerClass")]
    public static Class LayerClass () {
        return new Class (typeof (CATiledLayer));
    }
}
  

If you want to subclass the CALayer class, you must provide a constructor that takes a CALayer and is annotated with an [Export ("initWithLayer:")] attribute. When you do this, you should also override the CALayer.Clone (CALayer) as these two are used to create copies of your layer state on demand in response to CoreAnimation creating a mirror of your object hierarchy if anyone accesses the CALayer.PresentationLayer property.

C# Example

public class MyLayer : CALayer {
	UIColor FirstColor, SecondColor;

	//
	// Invoked by CoreAnimation if it needs to create a copy of your layer
	// with a specific state in response to the user fetching the PresentationLayer
	// property
	//
	[Export ("initWithLayer:")]
	public MyLayer (Mylayer other) : base (layer)
	{
		// Do nothing, since we override Clone, but we could
		// just clone the data here as well if we wanted to.
	}

	//
	// This is the constructor you would use to create your new CALayer
	public MyLayer (UIColor firstColor, UIColor secondColor)
	{
		FirstColor = firstColor;
		SecondColor = secondColor;
	}

	// We must copy our own state here from the original layer
	public override void Clone (CALayer _other)
	{
		MyLayer other = (MyLayer) _other;
		FirstColor = other.FirstColor;
		SecondColor = other.SecondColor;
	}
}
	

Related content

Requirements

Namespace: MonoMac.CoreAnimation
Assembly: XamMac (in XamMac.dll)
Assembly Versions: 0.0.0.0