我有一个 UIView,我在其中使用 autolayout
布置了各种 subview 。我在 interface builder
中以图形方式完成了此操作,布局在所有尺寸的设备的预览中都能正常工作。
此UIView 子类
没有覆盖任何默认方法的代码。
然后我使用以下代码将此 UIView 加载到我的 UIView Controller 中:
self.view.addSubview(UIView.loadFromNibNamed("SCPortraitCamera"))
self.view.setTranslatesAutoresizingMaskIntoConstraints(false)
let widthConstraint = NSLayoutConstraint(item: self.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: self.view.frame.width)
let heightConstraint = NSLayoutConstraint(item: self.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.Height, multiplier: 1, constant: self.view.frame.height)
self.view.addConstraint(widthConstraint)
self.view.addConstraint(heightConstraint)
这是在 viewdidLoad 中完成的。
UIView 显示正确,但它看起来不像任何 UIView subview 正在使用界面生成器中设置的自动布局约束。
非常感谢任何帮助。
最佳答案
有几个问题:
您可以引用这个指南:Autolayout Guide
或者这个问题:What is auto layout?
希望对您有所帮助。
关于ios - 自动布局 UIView Xcode 6 nib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28014393/