简体   繁体   English

ios - 模拟器看起来与故事板屏幕上的布局不同

[英]ios - simulator looks different from the layout on the storyboard screen

I am having a strange situation. 我有一个奇怪的情况。 I created a very simple screen with some buttons on the storyboard, then when I ran the emulator (is it correct to say simulator or emulator?) it got the spacing wrong for one of the buttons. 我创建了一个非常简单的屏幕,其中有一些按钮在故事板上,然后当我运行模拟器时(说模拟器或模拟器是否正确?),其中一个按钮的间距错误。

I am adding a screenshot. 我正在添加截图。 The emulator is to the right of the storyboard screen. 模拟器位于故事板屏幕的右侧。

Any idea why this may happen? 知道为什么会这样吗?

在此输入图像描述

I thought it was a problem with the button. 我认为按钮有问题。 And it might have been. 它可能是。 But when I took out two lower buttons, I got something even weirder as shown on this screenshot: 但当我拿出两个较低的按钮时,我得到的东西甚至更奇怪,如截图所示:

在此输入图像描述

Thanks! 谢谢!

It looks like you are using Autolayout, and all your buttons except Investment has a Top constraint while Investment has a Bottom constraint, causing Investment's distance to bottom to stay the same when the screen grows taller. 看起来你正在使用Autolayout,除了Investment之外的所有按钮都有一个Top约束,而Investment有一个Bottom约束,当屏幕变得更高时,导致投资距离底部的距离保持不变。

Click on Investment button, click [Editor -> Pin -> Top space to Superview] in the top menu. 单击投资按钮,在顶部菜单中单击[编辑器 - >固定 - >顶部空间到超级视图]。

Click Investment button again. 再次单击投资按钮。 Click the second tab from the right in the right panel (the one where you can set frame). 单击右侧面板右侧的第二个选项卡(可以设置框架的选项卡)。 Look for a Top Space to Superview constraint, right click and delete. 查找Topview to Superview约束,右键单击并删除。 If there isn't one, then XCode did its job. 如果没有,那么XCode就完成了它的工作。 Try running simulator again. 再试一次运行模拟器。

Edit: I just want to say that XCode has a habit of adding Top constraints for you when the view you just dragged into the xib is in the upper half of its container, and Bottom constraints when it's in the bottom half. 编辑:我只是想说,当你刚刚拖入xib的视图位于其容器的上半部分时,XCode有习惯为你添加Top约束,而当它位于下半部分时则是Bottom约束。 I know XCode is trying to help but it drives me crazy sometimes. 我知道XCode正试图提供帮助,但它有时会让我发疯。

It looks like you're using a 3.5" simulator and laying out for a 4" device, so the view will be resized. 看起来你正在使用3.5英寸模拟器并为4英寸设备进行布局,因此视图将被调整大小。

If you're using autoresize masks, are some of the autoresize masks on your buttons incorrect? 如果你正在使用自动调整大小的掩码,你的按钮上的一些自动调整大小的掩码是不正确的? You probably want them all to stick to the top of the screen. 您可能希望它们都粘在屏幕顶部。 Check to make sure the autosizing for each of your buttons matches this image. 检查以确保每个按钮的自动调整大小与此图像匹配。 (You'll need to click the "ruler" icon to see these settings.) (您需要单击“标尺”图标才能看到这些设置。)

autoresize pic

I assume that you're using the XCode4 which provides NSAutoLayout as default. 我假设您正在使用提供NSAutoLayout作为默认值的XCode4。 When you place an object to the storyboard NSAutolayout automatically creates constrains which layouts the object on the screen automatically for different devices(iPhone4,iPhone5) or orientations(portrait/landscape). 当您将对象放置到故事板时,NSAutolayout会自动创建约束,这些约束会自动为不同的设备(iPhone4,iPhone5)或方向(纵向/横向)布置屏幕上的对象。 Please check NSAutolayout class and constrains. 请检查NSAutolayout类和约束。 if you want you can remove the NSAutolayout and your objects will be displayed on the simulator normal but in that case you have to manually adjust your objects for different orientations and screens 如果你想要你可以删除NSAutolayout,你的对象将显示在模拟器正常,但在这种情况下你必须手动调整对象的不同方向和屏幕

Hope helps. 希望有所帮助

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

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