xcode iOS 模拟器/界面生成器偏离中心
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24946346/
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
iOS Simulator/Interface Builder off-center
提问by josmek
In interface builder I placed a button here:
在界面生成器中,我在这里放置了一个按钮:
However when I run the iOS Simulator (device: iPhone 5s) it appears here:
但是,当我运行 iOS 模拟器(设备:iPhone 5s)时,它会出现在这里:
I am using Xcode 6 Beta 4
我正在使用 Xcode 6 Beta 4
回答by CarlosGz
I would recommend you to use size classes due to new iOS screen sizes, but you still can disable size classes on the interface builder in the file inspector as you can see on the image:
由于新的 iOS 屏幕尺寸,我建议您使用尺寸类,但您仍然可以在文件检查器的界面构建器上禁用尺寸类,如您在图像中看到的:
If you would like to use Autolayout you can do it adding the next constraints (see the first image) in the corresponding View. In the second step you should use the width and height corresponding to your View. In the second image you can see a recapitulation of all the constraints and a simulator screenshot. Images:
如果您想使用自动布局,您可以在相应的视图中添加下一个约束(参见第一张图片)。在第二步中,您应该使用与您的视图相对应的宽度和高度。在第二张图片中,您可以看到所有约束的概括和模拟器屏幕截图。图片:
回答by Fogmeister
This is not actually anything to do with size classes. This is due to the fact that it is assuming you have placed it approx. 200 points from the left edge.
这实际上与尺寸等级无关。这是因为它假设您已经放置了大约。距左边缘 200 点。
What you haven't done is added AutoLayout constraints to say that you actually mean the centre.
您还没有做的是添加 AutoLayout 约束来说明您实际上是指中心。
CTRL-drag from the button to the view and add...
按住 CTRL 键从按钮拖动到视图并添加...
Center X values
Top space to superview
(Or something like those)
(或类似的东西)
Tha will make it work.
Tha将使它起作用。
回答by Samuel Tulach
回答by Joseph Gamache
(Xcode 10.1) In the small Triangle Menu: Select "Clear Constraints"
(Xcode 10.1) 在小三角菜单中:选择“清除约束”
Then Select "Add Missing Constraints"
然后选择“添加缺少的约束”
You can also manually adjust constraints by selecting one in the scene.
您还可以通过在场景中选择一个来手动调整约束。
Then grab the constraint handle.
然后抓住约束手柄。