說說anchorPoint,anchorpoint

來源:互聯網
上載者:User

說說anchorPoint,anchorpoint

anchorPoint屬性是CGPoint(x,y) ,x,y的取值是按比例取值,一般用0~1,預設是(0.5,0.5),表示圖層的position在自身的位置,舉個例子,

在紅色view確定完大小位置後,如果修改layer的錨點也就是anchorPoint,會讓紅色view的中心點position發生位移,此時的錨點在箭頭指向的地方,anchorPoint的取值是layer左上方是(0,0),右下角是(1,1),layer的中心因為anchorPoint的改變而改變,anchorPoint參考左上方(1,1),右下角(0,0)來改變layer中心點的位置,本例中anchorPoint = (0.5,1),那麼視圖就會向上移動0.5個layer的height,此時anchorPoint在箭頭所在位置, 

 

anchorPoint本質上就是個點,只是在視圖frame先確定的情況下,會讓layer的中心點改變,anchorPoint的取值是依託於layer的,

本題中如果先寫v.layer.anchorPoint,後寫v.frame,那麼視圖的中心不變,只是錨點的座標發生了變化而已,因為錨點在layer位置不存在的時候沒辦法改變layer的中心點

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.