標籤:
frame,bounds,center,position,anchorPoint總結
圖層的 position 屬性是一個 CGPoint 的值,它指定圖層相當於它父圖層的位置, 該值基於父圖層的座標系。
圖層的 bounds 屬性是一個 CGRect 的值,指定圖層的大小(bounds.size)和圖層的 原點(bounds.origin)。當你重寫圖層的重畫方法的時候,bounds 的原點可以作為圖形 內容相關的原點。
圖層擁有一個隱式的 frame,它是 position,bounds,anchorPoint 和 transform 屬性 的一部分。設定新的 frame 將會相應的改變圖層的 position 和 bounds 屬性,但是 frame 本身並沒有被儲存。但是設定新的 frame 時候,bounds 的原點不受幹擾,bounds 的大 小變為 frame 的大小,即bounds.size=frame.size。
圖層的位置被設定為相對於錨點 (anchor point)的適合位置。當你設定 frame 的值的時候,它的計算方式和 position、 bounds、和 anchorPoint 的屬性相關。
當你設定圖層的 frame 屬性的時候,position 會根據錨點(anchorPoint)相應的改 變,而當你設定圖層的 position 屬性的時候,bounds 會根據錨點(anchorPoint)做相應 的改變。
frame,center和bounds屬性
1.frame、center和bounds屬性
- frame:控制位置和大小
- center:控制位置(中心點)
- bounds:控制大小(以自己的左上方為原點)
2.注意點
(1)通過以下屬性可以修改控制項的位置
(2)通過以下屬性可以修改控制項的尺寸
position,anchorPoint
- position:是我們需要設定對用控制項的一個位置
比如:btn.position = CGPointMake(0, 0);我們對應控制項的位置就是(0,0)
但是你想想控制項中有無數個點,你怎麼知道那個點作為我們要設定的那個點呢,當然我們按常理來都是中心點,但是這並不唯一,所以就有了anchorPoint
- anchorPoint:覺得控制項上面的那個點是我要設定的對應的點
有時候我們會結合上面幾個屬性使用,但是根據需求anchorPoint一般是用來實現不是繞中心點旋轉功能,二如果我們不修改anchorPoint的話,position預設就是中點(父控制項)
iOS開發——使用OC篇&frame,bounds,center,position,anchorPoint總結