frame,bounds,center之間的關系
Frame A (CGRect)表示其在superview的坐標系中的矩形位置。默認從左上開始。location(x,y), size(width,height).
Bounds A (CGRect)表示其在自身坐標系中矩形位置。默認location(x,y)為(0,0),size(width,height).
Center A (CGPoint)表示在其superview的坐標系中的位置。
有以下幾個結論(前提是view沒有旋轉)
frame.origin = center - (bounds.size / 2.0)
center = frame.origin + (bounds.size / 2.0)
frame.size = bounds.size
所以說 如果你一直認為view.frame.size = view.bouds.size,那么很遺憾的告訴你這個想法是錯誤的。因為如果view發生了旋轉,結果就不是你想象的那個樣子了。
1.png
例子中是一旋轉了的圖片,所以frame.size != bounds.size.
當你在一個view自身的坐標系內處理畫圖的時候,通常使用bounds屬性。
對于一個view,當你改變了它的bounds.size,那么它的frame也會隨之改變(反之亦然)。而且這個改變是圍繞view的center改變的。
當父view的bounds.origin改變,會影響其子view在父view中的位置。因為子view在父view中的布局是相對父view..bounds.origin=>(0,0)時的布局。
2.png
CGRect rect = [[self view] bounds];
rect.origin.x += 30.0f;
rect.origin.y += 20.0f;
[[self view] setBounds:rect];
3.png
可以看出 子view位置變化了。