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。