简体   繁体   English

Xcode - 使用约束

[英]Xcode - using constraints

I'm trying to expand an UIView into all available space on its parent, setup such constraints 我正在尝试将UIView扩展到其父级的所有可用空间,设置这样的约束

在此输入图像描述

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. 绿色矩形始终与顶部相距64px,与您声明的完全相同。

When in portrait the UINavigationBar is 44px height, but when in lanscape it is 32px. 在肖像中, UINavigationBar的高度为UINavigationBar ,但在lanscape中为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. 如果您希望它在导航栏的0px处,则可以在矩形和顶部布局指南之间放置0px的约束。

You created a constraint that has a fixed distance to the (container) view of 64 pixels. 您创建了一个与64像素的(容器)视图具有固定距离的约束。 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. 顶部布局指南将确保视图的顶部将是准确的,具体取决于UIStatusBarUINavigationBar组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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