frame 和 bounds 是 UIView 的两个属性:
Frame: Size and location of view within superview's coordinate system.
Frame 是指该 view 在 父 view 中的大小和位置,是以父 view 的坐标作为参考。
Bounds: Size and content origin of a view in its own coordinate system.
Bounds 是指该 view 在自身坐标系统中的位置和大小,是以当前 view 的坐标作为参考。
注意:
1. bounds 的 origin 一定是 (0, 0)。
2. 当改变 frame 的 origin 时,其实改变的是该 view 在父 view 中的位置。而改变 bounds 的 origin 时, 改变的却是该 view 的子 view 在当前 view 中的位置。
3. bounds 的 size 与 frame 的 size 在大多数的情况下是相同的,但是在 view 进行旋转等操作后,这两个值就会出现差别。如下图,bounds 的 size 是 (200, 250),而 frame 的 size 是 (320, 320)。