8

要支持这样的纵向和横向UIView

  +-------------------+
  | +---------------+ |
  | |               | |
  | |     Fixed     | |
  | |      size     | |
  | |     Square    | |
  | |               | |
  | +---------------+ |   Protrait
  | +---------------+ |
  | |   Flexible C  | |
  | +---------------+ |
  | +---+       +---+ |
  | | A |       | B | |
  | +---+       +---+ |
  +-------------------+

  +----------------------------------+
  | +---------------+ +------------+ |
  | |               | |  Flexible  | |
  | |    Fixed      | |     C      | |
  | |     size      | +------------+ |
  | |    Square     | +---+    +---+ |
  | |               | | A |    | B | |
  | +---------------+ +---+    +---+ |
  +----------------------------------+
               Horizontal

我需要手动重新定位子视图willRotateToInterfaceOrientation吗?或者可以Autolayout自动为我做吗?

  • B是一个按钮总是停留在右下方
  • A是相对于B(最好与 的左侧对齐C)定位的按钮
  • C用于文本,大小灵活
  • A并且B在下面C
4

1 回答 1

6

In this case you should be able to get most of the layout work done automatically, but with a couple slight adjustments upon rotation.

What I would suggest is to contain views A, B, and C in another UIView. That way, the orientation-dependent layout is separate from the flexibly-sized layout. It also makes the layout a lot simpler to code!

Then you lay out the square view and the container view somewhat like this:

H:|-10-[squareView]
V:|-10-[squareView]
H:[containerView]-10-|
V:[containerView]-10-|
squareView.width == squareView.height

Notice that the square view is always aligned with the left and top of the superview, while the container view is aligned with the bottom and right. For a portrait orientation, you would add these constraints:

V:[squareView]-10-[containerView]
H:[squareView]-10-|
H:|-10-[containerView]

And for a landscape orientation, you would invert those constraints:

H:[squareView]-10-[containerView]
V:[squareView]-10-|
V:|-10-[containerView]

That's just for the overall layout, so the flexible sizing of the container view's subviews is up to you. Hope this helps!

于 2013-07-31T05:48:49.097 回答