UIView and CALayer
CALayer is included in the QuartzCore framework, CALayer is mainly responsible for drawing, UIView is mainly responsible for interaction.
The essence of animation development with CoreAnimation is to convert the contents of CALayer into bitmaps for hardware operation.
Layer operation:
view,layer.cornerRadius = 10;
UIWindow is a subclass of UIView, and its job is to provide an area to display UIView and distribute events to UIView.
Common layers are:
CATextLayer:
Used to achieve flexible text layout and rendering
CAShapeLayer:
Used to draw vector graphics, you can specify line width and color using CGPath to draw graphics path.
Advantages: 1. Fast rendering speed, the use of hardware acceleration to draw graphics.
2. More efficient memory usage, no need for VIEW as a carrier;
3. Beyond the coating boundary will not be cut off;
CAGradientLayer:
Achieve a variety of color smooth gradient effect
CATransformLayer:
3D graphics change
CAScrollLayer:
Scroll to view
Off-screen rendering:
Change layer parameters, such as view.layer.cornerRadius = 5.
view.layer.maskToBounds = YES;
Current screen render:
Do not need to create a buffer, also do not need to switch the buffer, relatively efficient
Crop through bezierPath
The contentsScale property is used to support high-resolution screens and defines the ratio of the layer pixel size to the view size, which defaults to 1.
When contentsScale=2 means that a dot on the screen represents two pixels, it’s a Retina display.
The Retina screen has four pixels per dot and a scale of two.
It can be set like this:
layer.contentsScale = [UIScreen mainScreen].scale;
The relationship among frame, position and anchorPoint:
frame.origin.x = position.x – anchorPoint.x*bounds.size.width;
frame.origin.y = position.y – anchorPoint.x*bounds.size.width;
Implicit animation:
The default is to change linearly from an initial state to a target state.
[UIView animateWithDuration: 0.5 animations: ^{
view.center = self.view.center;
} completion:^(BOOL finished){
}]
Explicit animation:
Explicitly define the complete animation flow that can be moved along a curve.
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@”transformPath”];
CATransform3D scaleTransform = CATransform3DMakeScale (1.2, 1.2, 1); / / 3 d scaling
animation.toValue = [NSValue valueWithCATransform3D:scaleTransform];
Animation. Duration = 0.5;
animation.repeatCount = 1;
[view.layer addAnimation:animation forKey:@”animationScaleKey”];
CGAffineTransform:
CGAffineTransformMakeTranslation(CGFloat x,CGFloat y);
CGAffineTransformMakeScale(CGFloat sx,CGFloat sy);
CGAffineTransformMakeRotation(CGFloat angle);
CGTransform3D:
CGTransform3DMakeTranslation(CGFloat x,CGFloat y,CGFloat z);
CGTransform3DMakeScale(CGFloat sx,CGFloat sy,CGFloat sz);
CGTransform3DMakeRotation(CGFloat angle, CGFloat x,CGFloat y,CGFloat z);
Control the perspective of the 3D transform by modifying the M24 property.
CATransition animation: