tips:
1.ScrollView的滾動效果就是利用了修改bounds來實現(xiàn)的!!!!(拓展知識)
(bounds.origin就是scrollView的offset值相同,其實scrollView的contentInset本質(zhì)也是修改bounds)
特別值得注意的是
為什么我們的contentsize跟frame相同還是可以滾動?
self.automaticallyAdjustsScrollViewInsets不設(shè)置no的話,系統(tǒng)內(nèi)部修改了contentInset,增加了contentSize 64,所以可以滾動了;
2.position是layer中的anchorPoint在superLayer中的位置坐標荔睹。(position就是center)
(position就是center,anchorPoint就是layer上的哪個位置對準position)
3.互不影響原則:單獨修改position與anchorPoint中任何一個屬性都不影響另一個屬性。
4.frame言蛇、position與anchorPoint有以下關(guān)系:
frame.origin.x = position.x - anchorPoint.x * bounds.size.width;
frame.origin.y = position.y - anchorPoint.y * bounds.size.height;
第2條的互不影響原則還可以這樣理解:position與anchorPoint是處于不同坐標空間中的重合點僻他,修改重合點在一個坐標空間的位置不影響該重合點在另一個坐標空間中的位置。
正文
UIView有三個比較重要的布局屬性:frame腊尚,bounds和center吨拗,CALayer對應(yīng)地叫做frame,bounds和position跟伏。為了能清楚區(qū)分丢胚,圖層用了“position”,視圖用了“center”受扳,但是他們都代表同樣的值携龟。
frame:content(內(nèi)容物)在其父界面元素中的位置和大小。
bounds:content(內(nèi)容物)在其自身坐標系統(tǒng)中的位置和大小勘高。(bounds就是scrollView的offset值相同,其實scrollView的contentInset本質(zhì)也是修改bounds)
center:描述當前界面元素的中心點在其父界面元素中的位置,圖層用了“position”峡蟋,視圖用了“center”,但是他們都代表同樣的值华望。
(position就是center,anchorPoint就是layer上的哪個位置對準position)
一般我們可以通過以下公式得出center:
center.x?=?frame.origin.x?+?frame.size.width?*?0.5;
center.y?=?frame.origin.y?+?frame.size.height?*?0.5;
視圖的frame蕊蝗,bounds和center屬性僅僅是儲方法,當操縱frame赖舟,實際上改變位下視圖下CAlayer的frame,不能獨立于圖層外改變視圖的frame!!!
對于視圖或者圖層來說蓬戚,frame并不是一個非常清晰的屬性,它其實是一個虛擬屬性宾抓,是根據(jù)bounds子漩,position和transform計算而來,所以當其中任何一個值發(fā)生改變石洗,frame都會變化幢泼。相反,改變frame的值同樣會影響到他們當中的值讲衫。