xcode 将视图复制到带有导航控制器的项目 - “图像视图”的框架在运行时会有所不同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21382158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:35:57  来源:igfitidea点击:

Copied a View to a project with Navigation Controller - Frame for "Image View" will be different at run time

iosxcodeinterface-builderxcode5

提问by Alexander Farber

Probably a simple question for experienced Xcode 5 interface builder users, but it is difficult to find the answer on Google:

对于有经验的 Xcode 5 界面构建器用户来说可能是一个简单的问题,但很难在谷歌上找到答案:

I have an app for iPhone, which doesn't use a navigation controller (here fullscreen):

我有一个 iPhone 应用程序,它不使用导航控制器(这里是全屏):

xcode screenshot

Xcode截图

The view scene on the very right side has an image view and 5 labels underneath it - to display user details:

最右侧的视图场景有一个图像视图和下面的 5 个标签 - 显示用户详细信息:

app screenshot

应用截图

Then I have created another iPhone appand copied that "details" view to it (here fullscreen):

然后我创建了另一个 iPhone 应用程序并将“详细信息”视图复制到它(这里是全屏):

xcode screenshot

Xcode截图

And now a warning is shown by Xcode 5.0.2:

现在 Xcode 5.0.2 显示警告:

Frame for "Image View" will be different at run time.

“图像视图”的框架在运行时会有所不同。

Is it because some space on the top of the view will be occupied by the navigation bar?

是不是因为视图顶部的一些空间会被导航栏占用?

And how to fix it please?

以及如何解决?

I've tried clicking the [-o-]icon, but instead of resolving my layout issue it has messed the whole layout (the labels jumped to the left).

我试过单击[-o-]图标,但没有解决我的布局问题,而是弄乱了整个布局(标签跳到左侧)。

Also I've tried setting checkboxes on the right side in the Xcode Attributes Inspector, but haven't be able to find any good combination there (and I am not sure what "inferred" means in Xcode context).

此外,我尝试在 Xcode Attributes Inspector 的右侧设置复选框,但无法在那里找到任何好的组合(我不确定“推断”在 Xcode 上下文中的含义)。

UPDATE:

更新:

Ossir's suggestion has worked for me, thank you.

Ossir 的建议对我有用,谢谢。

I'm posting a new screenshot (here fullscreen) in case anybody have more improvement suggestions:

我正在发布一个新的屏幕截图(这里是全屏),以防有人有更多改进建议:

xcode screenshot

Xcode截图

采纳答案by Ossir

Select the UIImageViewand click [-o-]icon, then choose Reset To Suggested Constraintsmenu item. Simulated metricssection does nothing in the runtime, it only us to figure out how layout will look like before compiling.

选择UIImageView并单击[-o-]图标,然后选择Reset To Suggested Constraints菜单项。 模拟指标部分在运行时什么都不做,只有我们在编译之前弄清楚布局的样子。

Also there is one more (better) approach, but you have to analyse what constraints UIImageViewhas and change them accordingly for new layout (with added nav bar). You can try to post screenshot with those constraints here, so we can help you to figure out what happened. Go to Size Inspectorin right panel and show us Constraintssection.

还有一种更多(更好)的方法,但您必须分析有哪些约束UIImageView并相应地更改它们以用于新布局(添加导航栏)。您可以尝试在此处发布带有这些限制的屏幕截图,以便我们帮助您弄清楚发生了什么。转到右侧面板中的Size Inspector并向我们​​展示Constraints部分。

UPDATE

更新

Your constraints force UIImageViewto have the same horizontal align as labels below have and the same width. Plus you have constraints for fixed vertical space from the topmost label and navigation bar, width of UIImageViewdepends on available space between nav bar and labels. I think it's good solution for current layout (without scrolling), because everything will fit into the screen for both 3.5" and 4" inch displays. In case you want different behaviour let me know in a comments.

您的约束强制UIImageView与下面的标签具有相同的水平对齐方式和相同的宽度。此外,您对顶部标签和导航栏的固定垂直空间有限制,宽度UIImageView取决于导航栏和标签之间的可用空间。我认为这是当前布局的好解决方案(无需滚动),因为 3.5" 和 4" 英寸显示器的所有内容都适合屏幕。如果您想要不同的行为,请在评论中告诉我。

回答by Damo

I found that unchecking the Adjust Scroll View Insets checkbox for the navigation controller in question cleared the warning

我发现取消选中有问题的导航控制器的“调整滚动视图插入”复选框清除了警告

Adjust Scroll View Insets

调整滚动视图插入

回答by Vladimir Romanov

Just faced the same warnings in Xcode version 8.0 Swift 3.0. The warning went away after I checked and unchecked the "Adjust Scroll View Insets" option. Note: they were not checked at the start like in the comment above, so it may clarify for those who have this same warning.

刚刚在 Xcode 8.0 Swift 3.0 版中遇到了同样的警告。在我选中并取消选中“调整滚动视图插入”选项后,警告消失了。注意:在开始时没有像上面的评论中那样检查它们,因此对于那些有相同警告的人来说可能会澄清。

Check/Uncheck the "Adjust Scroll View Insets" option.

选中/取消选中“调整滚动视图插入”选项。

enter image description here

在此处输入图片说明

回答by Alexis

It looks like you run your app on a 3.5" screen while you've been designing it for a 4" screen in interface builder. You should set all missing constraints so that autolayout 'knows' how to lay out your image view and labels.

看起来您在 3.5" 屏幕上运行您的应用程序,而您一直在界面构建器中为 4" 屏幕设计它。您应该设置所有缺少的约束,以便自动布局“知道”如何布局您的图像视图和标签。

I would set a fixed height for the labels and a variable height for the image view. Then set the content mode of your image view to "aspect fill" (note that in this case you'll loose a part of the image instead of having gray stripes on the left and right sides).

我会为标签设置一个固定的高度,为图像视图设置一个可变的高度。然后将图像视图的内容模式设置为“纵横比填充”(请注意,在这种情况下,您将丢失图像的一部分,而不是左右两侧有灰色条纹)。