ios - 当 `translatesAutoresizingMaskIntoConstraints` 设置 `NO` 时 View 消失

标签 ios autolayout

问题

使用了一些第三方库。某些 View 在它们的 translatesAutoresizingMaskIntoConstraints 设置为 NO 后消失。

在我自己的代码中,我的 View 没有其他 autoresizingMask 设置;在库中,代码的 autoresizingMask 部分也已被删除。相反,为这些 View 设置了明确的边界/中心/框架。没有 nib 文件, View 都是以编程方式创建的。

我知道其他一些人通过提供完整的自动布局约束集来解决类似问题,但就我而言,我的意思是关闭自动布局并手动执行。不知道自动版式何时打开。

有些人说“默认情况下,当您的应用程序启动时,自动布局会关闭,并且系统的行为与 iOS 5 及更早版本中的一样。但是,如果在您的应用程序运行时的任何时候,系统看到一个自动布局约束(在代码中生成或通过加载已选中“使用自动布局”的 Nib 生成),自动布局系统已打开,从那时起您将在自动布局下运行。” (Matt Neuberg 编写的 iOS 6 编程,第 383-384 页),但在我的项目中,我认为没有任何自动布局约束。

代码体积庞大,但如有必要会上传一些骨架。

感谢您的提示!

最佳答案

如果您不想使用自动布局,则必须将 translatesAutoresizingMaskIntoConstraints 设置为 YES。这是 a reference :

This works through the property translatesAutoresizingMaskIntoConstraints. When this property is YES, which it is by default, the autoresizing mask of a view is translated into constraints. For example, if a view is configured as in Figure 6-1 and translatesAutoresizingMaskIntoConstraints is YES, then the constraints |-20-[button]-20-| and V:|-20-[button(20)] are added to the view’s superview. The net effect is that unaware views behave as they did in versions of OS X prior to 10.7.

For views that are aware of Auto Layout, in most circumstances you will want translatesAutoresizingMaskIntoConstraints to be NO. This is because the constraints generated by translating the autoresizing mask are already sufficient to completely specify the frame of a view given its superview’s frame, which is generally too much. For example, this will prevent a button from automatically assuming its optimal width when its title is changed.

关于ios - 当 `translatesAutoresizingMaskIntoConstraints` 设置 `NO` 时 View 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19627825/

相关文章:

ios - UIBarButtonItemStyle Bordered、Done、Plain 有什么区别?

ios - 如何在 Swift 中扩展 NSManagedObject 以包含 MKAnnotation?

swift - 自动布局看起来因屏幕尺寸而异

IOS:AutoLayout UITableView -> UITableViewCell 未显示正确的大小

ios - 在哪里使用 CGPathRelease?

ios - Dropbox 登录应用程序图标

iphone - 从 CALayers 获取位图,renderInContext 的任何替代方法

ios - 为什么 UIView 的这些自动布局约束会阻止 UIButton subview 接收触摸事件?

ios - 键盘盖住iAd,怎么修?

ios - 使用自动布局将自定义 UIView 垂直和水平居中