简体   繁体   English

在ios / xcode中可以打开自动布局,但没有约束

[英]In ios/xcode is it ok to have autolayout turned on but have no constraints

I have a view controller that is working better without any constraints (formatting looks better on all iphone screens). 我有一个视图控制器,它在没有任何限制的情况下工作得更好(所有iPhone屏幕上的格式看起来都更好)。 However, I'm using autolayout for the rest of my view controllers so it's turned on at a global level. 但是,我在其余的视图控制器中使用了自动布局,因此在全局级别启用了自动布局。

Everything seems to be fine (there are no warnings) having no constraints on this view controller. 一切似乎都很好(没有警告),对此视图控制器没有任何约束。 Also, this VC has only has static text content and the app is locked in portrait mode. 此外,此VC仅具有静态文本内容,并且该应用程序被锁定为纵向模式。

I'm wondering if I'm missing something and need to have some constraints? 我想知道我是否缺少某些东西并需要一些约束?

Edit: I have cleared all the constraints, so there aren't any default constraints when I look at the VC. 编辑:我已经清除了所有约束,所以当我查看VC时没有任何默认约束。 When I select "Add missing constraints" the VC formatting looks bad. 当我选择“添加缺少的约束”时,VC格式看起来很糟糕。

Starting with Xcode 5, not adding any constraints to a hierarchy will make Xcode add a default constraints. 从Xcode 5开始,不向层次结构添加任何约束将使Xcode添加默认约束。 You are seeing those when you run your app and reach the view controller. 您在运行应用程序并到达视图控制器时会看到这些内容。 However, if you rotate your view, you'll notice that these constraints are very basic. 但是,如果旋转视图,您会注意到这些约束是非常基本的。 It would be better to have your own constraints, but if you only support one orientation, these constraints are fine. 拥有自己的约束会更好,但是如果仅支持一种方向,那么这些约束就可以了。

Here is a suggestion; 这是一个建议; run your project with the default constraints, and inspect in runtime to see what they are, and get ideas how to implement them in Xcode. 使用默认约束运行您的项目,并在运行时检查以了解它们是什么,并获得有关如何在Xcode中实现它们的想法。

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

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