故事板预览与 xCode 6 中的模拟器或设备不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26196180/
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 05:47:10  来源:igfitidea点击:

Storyboard Preview do not match simulator or device in xCode 6

xcodestoryboardios8xcode6

提问by b3rge

I have been trying to figure this out for a long time now, either I am stupid, or Apple hav just made this really tricky. Storyboard Preview do not match simulator or device in xCode 6! I have added constraints so that the app looks just fine in all screen sizes in preview but it looks messed up when I run it in the simulator or on my device. help!

很长一段时间以来,我一直试图弄清楚这一点,要么是我愚蠢,要么是 Apple 刚刚让这件事变得非常棘手。故事板预览与 xCode 6 中的模拟器或设备不匹配!我添加了约束,以便应用程序在预览中的所有屏幕尺寸下看起来都很好,但是当我在模拟器或我的设备上运行它时,它看起来很糟糕。帮助!

do you need any screenshots to answer my question?

你需要任何截图来回答我的问题吗?

I know other people have had the same issue but I can not find any answers.

我知道其他人也有同样的问题,但我找不到任何答案。

my project, everything looks just fine

我的项目,一切看起来都很好

the simulator does not look fine (this happens when I run the app on my phone as well, and it happens to all screen sizes in the simulator as well)

模拟器看起来不太好(当我在手机上运行应用程序时也会发生这种情况,并且模拟器中的所有屏幕尺寸也会发生这种情况)

回答by Justin Lewis

The storyboard "Preview" doesn't match the simulator if you have any constraint errors/conflicts. I was having this problem, and found this question while searching for an answer. Once I got all of the conflicts resolved, the Preview worked. It seems like the preview should consistently show what the simulator would show to help during the setup, but it's all out of whack if there are conflicts.

如果您有任何约束错误/冲突,故事板“预览”与模拟器不匹配。我遇到了这个问题,在寻找答案时发现了这个问题。一旦我解决了所有冲突,预览就起作用了。看起来预览应该始终如一地显示模拟器在设置过程中会显示的帮助内容,但如果存在冲突,那就完全不正常了。

回答by user1045302

Using Xcode 6.3.1 and I was having the same problem(s). What I discovered is that you are missing constraints... open main.storyboard in your "Structure" column you should see some red arrows, single click them and you should see what constraints you are missing.

使用 Xcode 6.3.1,我遇到了同样的问题。我发现您缺少约束...在“结构”列中打开 main.storyboard,您应该会看到一些红色箭头,单击它们,您应该会看到缺少哪些约束。

回答by H.Rabiee

Can confirm that this was resolved after taking care of all warnings and errors related to Auto Layout.

在处理与自动布局相关的所有警告和错误后,可以确认此问题已解决。

回答by Eric Mentele

I just fixed my size class problem by having my constraints be set for compact width / regular height. When I set constraints specific to compact width / any height, it ignored my custom values.

我只是通过将我的约束设置为紧凑宽度/常规高度来解决我的尺寸等级问题。当我设置特定于紧凑宽度/任何高度的约束时,它忽略了我的自定义值。

Hope that helps. Took me forever to figure out because the description lead me to believe my custom layout would cover more devices with the latter choice.

希望有帮助。我花了很长时间才弄明白,因为描述让我相信我的自定义布局会用后一种选择覆盖更多设备。

回答by KawaiKx

This is a constraints issue. Some constraints are not set properly or not set at all. Once all constraint issues are resolved, you would see the simulator and preview matching exactly!

这是一个约束问题。某些约束未正确设置或根本未设置。解决所有约束问题后,您将看到模拟器和预览完全匹配!

回答by Simon

For anyone experiencing this issue in Xcode 8 and all all your constraints are in place (i.e. no warnings or errors) what solved it for me was quittingthe simulator and restarting the app through Xcode again.

对于在 Xcode 8 中遇到此问题并且所有约束都已到位(即没有警告或错误)的人来说,解决它的方法是退出模拟器并再次通过 Xcode 重新启动应用程序。

回答by user1759949

Make sure you've got the latest xcode installed. I had the exact same problem before realising there was an update waiting. Now I've installed the update my preview matches what appears on the simulator.

确保你已经安装了最新的 xcode。在意识到有更新等待之前,我遇到了完全相同的问题。现在我已经安装了更新,我的预览与模拟器上显示的内容相匹配。

回答by Anil

How I got this fixed is by updating Xcode to the latest version. And then recreated the NIB/Storyboard files that were created using the previous version of Xcode. It started working. Weird fix :/

我如何解决这个问题是通过将 Xcode 更新到最新版本。然后重新创建使用先前版本的 Xcode 创建的 NIB/Storyboard 文件。它开始工作了。奇怪的修复:/