Farlanki.

frame,bounds和center

字数统计: 212阅读时长: 1 min
2015/12/29 Share

参考:http://stackoverflow.com/questions/5361369/uiview-frame-bounds-and-center

UIView中有两个和位置相关的属性,一个为frame,另一个为bounds.

frame

官方文档中是这样描述frame的:

1
The view’s frame rectangle, which defines its position and size in its superview’s coordinate system.

意思就是frame是指view在superview的坐标系统中的position和size.

bounds

官方文档中是这样描述bounds的:

1
The view’s bounds rectangle, which expresses its location and size in its own coordinate system.

意思就是bounds是在自己的坐标系统中表示location和size.

center

官方文档中是这样描述center的:

1
The center is specified within the coordinate system of its superview and is measured in points. Setting this property changes the values of the frame properties accordingly.

center使用的是superview的坐标系统,设置center会相应的改变view的frame属性.

它们之间的关系是:

  • frame.origin = center - (bounds.size / 2.0)

  • center = frame.origin + (bounds.size / 2.0)

  • frame.size = bounds.size

CATALOG
  1. 1. frame
  2. 2. bounds
  3. 3. center