(直接繼承于NSObject)
The CALayer class manages image-based content and allows you to perform animations on that content. Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer’s main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size, and transform) that is used to present that content onscreen. Modifying the properties of the layer is how you initiate animations on the layer’s content or geometry. A layer object encapsulates the duration and pacing of a layer and its animations by adopting the CAMediaTiming protocol, which defines the layer’s timing information.
calayer管理以圖像為基礎的內容,允許在內容之上進行動畫。它經常為視圖提供背景。(即使沒有視圖,它也能夠展示內容)它的主要功能事管理可見的內容。而且他也有自己可設置的屬性,例如背景色,邊界,陰影效果等。除了管理可見內容,它還可以管理內容的幾何學的屬性(例如位置,大小,和形狀矩陣),今兒控制它在屏幕上的顯示??梢酝ㄟ^改變涂層的屬性進行動畫操作。視圖通過遵守CAMediaTiming協議,可以控制動畫進行之中的時間效果。
Overview
If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a delegate object and use that object to provide the contents of the layer dynamically and perform other tasks. A layer may also have a layout manager object (assigned to the layoutManager property) to manage the layout of subviews separately.
綜述
如果涂層是被一個視圖類創建,視圖會自動將自己設置為涂層的代理屬性。而且你不應該改變這種關系。自行創建的涂層屬性,你可以設置代理值,動態改變它的內容,執行其它的操作。圖層有自己的布局對象管理它的字視圖。
CAShapeLayer
The CAShapeLayer class draws a cubic Bezier spline in its coordinate space. The shape is composited between the layer's contents and its first sublayer.
CAShapeLayer類在它的坐標系統中繪制貝賽爾曲線。圖形位于涂層的內容和它的第一層子圖層之間。
The shape will be drawn antialiased, and whenever possible it will be mapped into screen space before being rasterized to preserve resolution independence. However, certain kinds of image processing operations, such as CoreImage filters, applied to the layer or its ancestors may force rasterization in a local coordinate space.
Note
Shape rasterization may favor speed over accuracy. For example, pixels with multiple intersecting path segments may not give exact results.
1.類的主要功能是可以自己繪制各種各樣的曲線構成圖形(通過UIBezier的path的屬性)
簡單??:
CAShapeLayer * layer = [CAShapeLayer layer];
layer.backgroundColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:layer];
layer.strokeColor = [UIColor redColor].CGColor;
//? ? layer.fillColor = [UIColor yellowColor].CGColor;
UIBezierPath * path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(100, 100)];
[path addLineToPoint:CGPointMake(100, 200)];
[path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(320, 568)];
[path closePath];
layer.path = path.CGPath;
注意點:
1.如果曲線沒有形成一個完整的閉合的圖形,他會自己自動補全
2.給layer 的path賦值時,注意時path的CGPath屬性。