1.簡單介紹
CALayer有2個非常重要的屬性:position和anchorPoint
@property CGPoint position;
用來設置CALayer在父層中的位置
以父層的左上角爲原點(0, 0)
@property CGPoint anchorPoint;
稱爲"定位點"、"錨點"
決定着CALayer身上的哪個點會在position屬性所指的位置
以自己的左上角爲原點(0, 0)
它的x、y取值範圍都是0~1,默認值爲(0.5, 0.5)
2.圖示
anchorPoint
它的取值爲0~1
紅色圖層的anchorPoint爲(0,0)
紅色圖層的anchorPoint爲(0.5,0.5)
紅色圖層的anchorPoint爲(1,1)
紅色圖層的anchorPoint爲(0.5,0)
position和anchorPoint
添加一個紅色圖層到綠色圖層上,紅色圖層顯示到什麼位置,由position屬性決定
假設紅色圖層的position是(100,100)
到底把紅色圖層的哪個點移動到(100,100)的座標位置,由錨點確定的。
紅色圖層的錨點是(0,0)
紅色圖層的錨點是(0.5,0.5)
紅色圖層的錨點是(1,1)
紅色圖層的錨點是(0.5,0)