OS X Cocoa Auto Layout hidden elements

后端 未结 8 1840
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 17:06

I am trying to use the new Auto Layout in Lion because it seems quite nice. But I can not find good information about how to do things. For example:

I have two labels:

8条回答
  •  旧巷少年郎
    2021-01-31 17:51

    This is possible with auto layout, but doesn't exactly scale well.

    So, taking your example, let's say you have label A, and label B (or button or anything else really). First start by adding a top constraint to the superview for A. Then a vertical spacing constraint between A and B. This is all normal so far. If you were to remove A at this point, B would have ambiguous layout. If you were to hide it, it would still occupy it's space including the space between the labels.

    Next you need to add another constraint from B, to the top of the superview. Change the priority on this to be lower than the others (say 900) and then set it's constant to be standard (or other smaller value). Now, when A is removed from it's superview, the lower priority constraint will kick in and pull B towards the top. The constraints look something like this:

    Interface Builder screenshot

    The issue comes when you try to do this with a long list of labels.

提交回复
热议问题