简体   繁体   中英

Xcode - using constraints

I'm trying to expand an UIView into all available space on its parent, setup such constraints

在此输入图像描述

when I run the project in simulator it display ok in portrait mode it display ok, but when turning into landscape I do see a small white strip at the top

在此输入图像描述

What is wrong? Any other constraints are needed?

Thx

Why are you surprised?

The green rectangle is always at 64px from the top, exactly as you declared.

When in portrait the UINavigationBar is 44px height, but when in lanscape it is 32px. So in portrait you have:

 -----------------------------       ---
|           STATUS BAR        | 20px  |
|-----------------------------|       |
|           NAV BAR           | 32px  | 64px
|-----------------------------|       |
|            empty            | 12px  |
|-----------------------------|      ---
|            GREEN            | 

If you want it to be at 0px from the navigation bar, you can put a constraint of 0px between the rectangle and the top layout guide.

You created a constraint that has a fixed distance to the (container) view of 64 pixels. Do not make this constraint depend on the other view but the top layout guide. You'll find it in the left list. 在此输入图像描述

The top layout guide will assure that the top of the view will be accurate depending on what combination of UIStatusBar and UINavigationBar there will be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM