Master
Basic properties of Calayer
The relationship between Calayer and UIView
The role of position and Anchorpoint
Calayer
Basic use of Calayer
Properties of the Calayer
//Border Width (circle a piece out of the layer as a border)
Self.purpleView.layer.borderWidth = ten;
Border color
Self.purpleView.layer.borderColor = [Uicolor Redcolor]. Cgcolor;
//fillet
Self.purpleView.layer.cornerRadius = ten;
Shadow color
Self.purpleView.layer.shadowColor = [Uicolor Redcolor]. Cgcolor;
//Shadow deviation
Self.purpleView.layer.shadowOffset = Cgsizemake (10,10);
//Shadow opacity
self.purpleView.layer.shadowOpacity = 0.5;
//Cut out of borders (rounded corners cannot coexist with shadows unless the picture is rounded)
Self.purpleView.layer.masksToBounds = YES;
Note: If you only set the Fillet property of a layer in ImageView, the main layer is set, and the picture is in the
sub-layer, the child layer covers the main layer of the fillet, so it does not look like it is set, so you also need to set the
Maskstobounds property. Cut out the parts that are outside the main layer. You can see the rounded corners.
//three-dimensional scaling
Self.purpleView.layer.transform = Catransform3dmakescale (1.5,0.5,0);
Three-dimensional rotation (connecting the lines of origin and point 1,1,0, with this line rotated 45 degrees in the axial direction)
Self.purpleView.layer.transform = catransform3dmakerotation (m_pi_4,1,1,0) ;
//Use Layer two-dimensional rotation
//can pass which key path, in Official document search Catransform3d key paths
[Self.iconView.layer setvalue:@ (m_pi_2) forkeypath:@ "Transform.rotation"];
First, create a new layer
New Layer
Calayer *layer = [[Calayer alloc] init];
Calayer *layer = [Calayer layer];
Layer.backgroundcolor = [Uicolor Redcolor]. Cgcolor;
Layer.bounds = CGRectMake (0,0,100,100);
Layer.position = Cgpointmake (200,100);
Set content
Layer.contents = (ID) [UIImage [email protected]: "Lufy"]. Cgimage;
[Self.view.layer Addsublayer:layer];
Choice of UIView and Calayer
The doubts about Calayer
Ii. position and Anchorpoint
Position and Anchorpoint
Anchorpoint
Third, implicit animation
Iv. Custom layers (you don't need to do the context yourself, and a custom view requires a context)
1. Create a new Mjlayer, inherit from Calayer
2. Come to MJLAYER.M, implement Drawincontext: Method
The Drawincontext: method is called only if the Setneedsdisplay method is called clearly.
-(void) Drawincontext: (cgcontextref) CTX
{
Red (cannot use Uicolor)
Cgcontextsetrgbfillcolor (ctx,1,0,0,1);
Add Circle
Cgcontextaddellipseinrect (Ctx,cgrectmake (0,0,50,50));
Solid drawing
Cgcontextfillpath (CTX);
}
3. Come to Mjviewcontroller's Viewdidload method
{
Mjlayer *layer = [Mjlayer layer];
Layer.bounds = CGRectMake (0,0,100,100);
Layer.backgroundcolor = [Uicolor Redcolor]. Cgcolor;
Layer.anchorpoint = Cgpointzero;
[Layer Setneedsdisplay];
[Self.view.layer Addsublayer:layer];
}
PS: Using proxy method to draw
Self.view.layer.delegate = = Self.view//view The proxy for that layer inside is the view itself,
So how the view layer is drawn is determined by the view. So view to implement Drawinrect method to draw
Look, remember, you can't set the proxy to self (controller)
PS: A proxy for a view's inner layer cannot be modified. A view cannot be a proxy for other layers.
How does the view come out?
View display depends on the layer, the view can be displayed because the view is about to show when the view of the
The layer prepares a layer Graphics context (the type of layers) to prepare the context
After that, the layer's proxy method is called Drawlayer:incontext: method, which will send and receive to the agent,
Drawlayer:incontext: The internal implementation of the method also calls Drawinrect: Method
iOS Advanced-quartzcore Framework-calayer layer