iOS開發——使用OC篇&frame,bounds,center,position,anchorPoint總結

來源:互聯網
上載者:User

標籤:

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)通過以下屬性可以修改控制項的位置

  • frame.origin
  • center

(2)通過以下屬性可以修改控制項的尺寸

  • frame.size
  • bounds.size

 

position,anchorPoint

  • position:是我們需要設定對用控制項的一個位置

      比如:btn.position = CGPointMake(0, 0);我們對應控制項的位置就是(0,0)

      但是你想想控制項中有無數個點,你怎麼知道那個點作為我們要設定的那個點呢,當然我們按常理來都是中心點,但是這並不唯一,所以就有了anchorPoint

  • anchorPoint:覺得控制項上面的那個點是我要設定的對應的點

 

有時候我們會結合上面幾個屬性使用,但是根據需求anchorPoint一般是用來實現不是繞中心點旋轉功能,二如果我們不修改anchorPoint的話,position預設就是中點(父控制項)

iOS開發——使用OC篇&frame,bounds,center,position,anchorPoint總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.