iOS模拟器按钮未居中 [英] iOS Simulator button not centered
问题描述
我正在按照教程制作一个非常简单的游戏,但我遇到了一个我无法弄清楚的问题。当我将我的按钮放在编辑器屏幕上时,它看起来都很好,但是在模拟器中运行应用程序似乎搞砸了所有内容:
I'm following a tutorial to make a very simple game, yet I've run into a problem I can't figure out. When I center my button on the editor screen it all looks fine, but then running the app in the simulator seems to screw it all up:
我正在运行最新版本的XCode。
I'm running the latest version of XCode.
推荐答案
您需要使用autolayout在按钮上设置一些约束。如果不使用autolayout,则布局仅使用原始X和Y值。所以在风景中,屏幕的高度是相同的,但宽度是不同的。您的按钮在两个屏幕上以相同的X值布局,因此一个将居中,一个不会。
You need to use autolayout to set some constraints on the button. If you don't use autolayout, the layout just uses the raw X and Y values. So in landscape, the heights of the screen are the same, but the widths are different. Your button lays out at the same X value on both screens, so one will be centered and one won't be.
签出本教程了解有关布局约束的更多信息。
Check out this tutorial for more info on layout constraints.
这篇关于iOS模拟器按钮未居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!