CALayer官方文檔

(直接繼承于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管理以圖像為基礎(chǔ)的內(nèi)容,允許在內(nèi)容之上進(jìn)行動畫。它經(jīng)常為視圖提供背景。(即使沒有視圖,它也能夠展示內(nèi)容)它的主要功能事管理可見的內(nèi)容。而且他也有自己可設(shè)置的屬性,例如背景色,邊界,陰影效果等。除了管理可見內(nèi)容,它還可以管理內(nèi)容的幾何學(xué)的屬性(例如位置,大小,和形狀矩陣),今兒控制它在屏幕上的顯示??梢酝ㄟ^改變涂層的屬性進(jìn)行動畫操作。視圖通過遵守CAMediaTiming協(xié)議,可以控制動畫進(jìn)行之中的時間效果。

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.

綜述

如果涂層是被一個視圖類創(chuàng)建,視圖會自動將自己設(shè)置為涂層的代理屬性。而且你不應(yīng)該改變這種關(guān)系。自行創(chuàng)建的涂層屬性,你可以設(shè)置代理值,動態(tài)改變它的內(nèi)容,執(zhí)行其它的操作。圖層有自己的布局對象管理它的字視圖。


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類在它的坐標(biāo)系統(tǒng)中繪制貝賽爾曲線。圖形位于涂層的內(nèi)容和它的第一層子圖層之間。

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.類的主要功能是可以自己繪制各種各樣的曲線構(gòu)成圖形(通過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屬性。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,940評論 0 23
  • 投資成功的核心方法論,簡單到令人發(fā)指的地步: 低買高賣 沒了!沒了?。〕酥?,真的沒有任何其它更為重要,或者同等...
    越來越好伍新國閱讀 337評論 0 1
  • 001 見過不要臉的,但沒見過這么不要臉的。我們編輯部的人正準(zhǔn)備下班吃飯,我不小心把稿子的最后一個符號弄錯了,顧...
    凌之煙閱讀 283評論 0 0
  • 2計算機組成原理 源碼:無法進(jìn)行運算 反碼: 正數(shù)--->反碼--->不變 負(fù)數(shù)--->反碼--->符號位1不變,...
    sunflower1518閱讀 353評論 1 0
  • 看到“失控"兩字,“砍手”這個詞立馬跳到了我面前。是的,我逛街必買東西,而且一買就超標(biāo)。經(jīng)常有的沒的都愛...
    芝芝1981閱讀 182評論 2 2