iOS中,設置view在父view中的位置和大小時,只須要設置frame就能夠了。frame是相對於superview座標系的,而bounds則相對於view自身的座標系,可是frame到底是怎樣表示座標的呢,這就和bounds有關了。atom
frame.size 和bounds.size 同樣,可是UIView中,frame實際上是不存儲的,而是動態計算的,改變center,改變bounds大小,或者改變transfrom均可能會致使frame的改變。 spa
UIView的frame是一個動態的,官方文檔中有提到code
// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.@property(nonatomic) CGRect frame;
orm
大意是說,若是咱們的view有transform,則frame不能反映其在父view中的實際位置,須要用bounds+center來反映。文檔
假定咱們的view沒有transform。 每次咱們設置frame時,則系統首先會設置it
bounds.origin = 0,0
io
bounds.size = frame.size
而後會繼續設置table
center.x = frame.origin.x + frame.size.width / 2
form
center.y = frame.origin.y + frame.size.height / 2
也就是說 設置frame時,咱們的bounds和center都會發生變化,可是view的位置是由center和bounds共同決定的,徹底能夠不依賴於frame。transform
每次咱們訪問frame時,其實也是經過center和bounds計算。
frame.size = bounds.size
frame.origin.x = center.x - bounds.size.width / 2
frame.origin.y = center.y - bounds.size.height / 2
固然期間若是有transform,則會考慮到transfrom,好比大小縮小到0.9倍,則center不變,frame.size 變爲 0.9倍,origin也會跟着變。 transform不會影響到view的bounds和center,可是會影響到frame。