3
votes

Using Auto Layout constraints, I am trying to set up a subview with a vertical position that never changes, even when the in-call status bar (or some other non-standard status bar) is showing. I don't want to position the view relative to the Bottom Layout Guide because I want its y-coordinate to be the same for 3.5" and 4" devices.

Here's an illustration of what I want to have happen:

Standard Status BarIn-Call Status Bar

Initially, I set up the subview with a "Top Space to: Top Layout Guide" constraint for its y-position. With this configuration, the In-Call Status Bar pushed the subview 20px downward:

Nope

Next, I tried replacing that constraint with "Top Space to: Superview," where Superview was the root view of the controller. No change. Is there some other way to maintain a constant y-position for a view with Auto Layout constraints? I know I could resort to handling this manually by subscribing to UIApplicationDidChangeStatusBarFrameNotification, but I'd like to keep things simple if I can.

2

2 Answers

1
votes

Your label is positioned to have a margin on top, between the start of the view and the start of the label. When the status bar grows, your view is shrunk. If you wish the label to remain in the same place, you can listen to UIApplicationWillChangeStatusBarFrameNotification notifications and adjust your view's size and origin to offset the additional space of the status bar. If you only want your label to shift up, you can also listen to the notification above, and adjust the top space constraint accordingly.

0
votes

No you cannot.

The frame looses 20 px height in Portrait :( and the layoutguides don't care about it.

So either you do what Leo Natan said and use the notifications UIApplicationWillChangeStatusBarFrameNotification Or either you will have to use the bottomConstraint as you dont want to do.