情节提要的视图与模拟器的视图不同 [英] Storyboard's view is different from simulator's view

查看:68
本文介绍了情节提要的视图与模拟器的视图不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切都在我的情节提要板上居中并以一种不错的格式进行了调整,但是看起来好像它在模拟器上向右对齐.选中使用自动版式"和使用尺寸类别"选项.我该如何解决这个问题?下面的屏幕快照显示了问题.

这是我的故事板上的样子:

这是在我的模拟器上:

关闭使用自动版式和使用尺寸类别"选项后,这是我的故事板:

解决方案

在Xcode 6中,默认的大小类别是"Any x Any",适合所有布局".这包括iPhone和iPad,默认的视图控制器的大小介于两者之间.您可以在情节提要的Interface Builder视图的底部,在带有约束控件的栏的中间找到此设置:

如您所见,与您要测试的iPhone相比,内容放置的视图非常宽.从情节提要中看来,您的视图似乎没有任何约束,这意味着它们将按原样显示.这意味着,当您在模拟器上进行测试时,所有内容似乎都向右移动-实际发生的事,那么,什么都没有!您拥有的视图的宽度要比iPhone的所有居中内容都要宽,并且要进行测试时,该视图是以实际大小绘制的(比iPhone宽),因为没有任何约束可以告诉它执行其他操作. /p>

您有两个相当简单的解决方案:

  1. 继续使用尺寸等级.您需要向视图添加约束,以使它们适应不同的屏幕尺寸.在这种情况下,最简单的操作是将所有内容放入容器视图中,并添加约束以使其与父视图居中对齐.如果只打算将iPhone定位,则可以将情节提要中的默认尺寸类别更改为紧凑宽度|常规高度",该尺寸类别将所有iPhone纵向定位.
  2. 禁用尺寸等级.您已经尝试过了-定位问题与我上面所述的相同.您的内容并没有真正居中对齐,只是放置在大视图的中心.您需要禁用尺寸类别,然后重新定位iPhone屏幕上的所有内容.

无论如何,您都需要添加约束以支持所有iPhone屏幕尺寸.因此,继续使用大小类会更容易-它们是Xcode 6的一个很酷的新功能!

Everything is centered and adjusted in a nice format on my storyboard, but it looks like it's aligned toward right on a simulator. "Use Auto Layout" and "Use Size Classes" options are checked. How can I resolve this issue? The screenshots below display the problem.

This is what it looks like on my storyboard:

This is on my simulator:

After I turn off "Use Auto Layout and Use Size Classes" options, this is my storyboard:

解决方案

In Xcode 6, the default size class is "Any x Any", which suits "all layouts". This includes iPhone and iPad, and the default view controller will have a size somewhere in between. You can find this setting at the bottom of the Interface Builder view for your Storyboard, in the middle of the bar with the constraint controls:

As you can see, the view that your content is placed in is very wide compared to the iPhone that you're testing on. From your storyboard it doesn't look like you've got any constraints on your views, which means they'll display as-is. This means that when you go to test it on the simulator, everything appears shifted to the right - what's actually happening is, well, nothing! You have a view that's wider than the iPhone with all your centered content, and that view is being drawn at actual size (wider than the iPhone) when you go to test it, because there are no constraints to tell it to do otherwise.

You have two reasonably easy solutions:

  1. Keep using size classes. You'll need to add constraints to your views so that they adapt to different screen sizes. The easiest thing to do in your situation is put all of your content in a container view and add constraints to center-align it to the superview. If you're only going to be targeting iPhone, you can change the default size class in your Storyboard to "Compact Width | Regular Height", which targets all iPhones in portrait orientation.
  2. Disable size classes. You have tried this already - the positioning problem is the same as I described above. Your content isn't really center aligned anywhere, it was just placed in the center of your large view. You'll need to disable size classes and then re-position all of your content for iPhone screens.

Regardless, you'll need to add constraints in order to support all iPhone screen sizes. Because of this, it's easier to just continue using size classes - they're a cool new feature of Xcode 6!

这篇关于情节提要的视图与模拟器的视图不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆