CAlayer層的屬性position和anchorPoint

1.簡單介紹

CALayer2個非常重要的屬性:positionanchorPoint

@property CGPoint position;

用來設置CALayer在父層中的位置

以父層的左上角爲原點(0, 0)

 

@property CGPoint anchorPoint;

稱爲"定位點""錨點"

決定着CALayer身上的哪個點會在position屬性所指的位置

以自己的左上角爲原點(0, 0)

它的xy取值範圍都是0~1默認值爲(0.5, 0.5


2.圖示

anchorPoint

它的取值爲0~1



紅色圖層的anchorPoint爲(00



紅色圖層的anchorPoint爲(0.50.5



紅色圖層的anchorPoint爲(11



紅色圖層的anchorPoint爲(0.50


positionanchorPoint

添加一個紅色圖層到綠色圖層上,紅色圖層顯示到什麼位置,由position屬性決定

假設紅色圖層的position是(100100

  到底把紅色圖層的哪個點移動到(100100)的座標位置,由錨點確定的。

  紅色圖層的錨點是(00



紅色圖層的錨點是(0.50.5



紅色圖層的錨點是(11



紅色圖層的錨點是(0.50



發佈了59 篇原創文章 · 獲贊 17 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章