使用自动布局使UIView全屏显示
我开始使用autolayout,我的UIViewController的self.view不再占据iPhone 6或iPhone 6plus的整个屏幕。UIView的大小为size=推断使用自动布局使UIView全屏显示,uiview,autolayout,Uiview,Autolayout,我开始使用autolayout,我的UIViewController的self.view不再占据iPhone 6或iPhone 6plus的整个屏幕。UIView的大小为size=推断 我在约束下查看了VC的主视图,约束编辑器不允许我选择视图的顶部、左侧、右侧和底部到窗口边缘的距离为0,0,0,0。我创建了一个函数,在UIView下添加一个白色遮罩(如果您是UIView的子类) func addBackgroundMask(){ backgroundMask = UIView()
我在约束下查看了VC的主视图,约束编辑器不允许我选择视图的顶部、左侧、右侧和底部到窗口边缘的距离为0,0,0,0。我创建了一个函数,在UIView下添加一个白色遮罩(如果您是UIView的子类)
func addBackgroundMask(){
backgroundMask = UIView()
backgroundMask?.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6)
backgroundMask?.setTranslatesAutoresizingMaskIntoConstraints(false)
let topConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Top, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Top, multiplier:1.0, constant:0.0)
let bottomConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Bottom, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Bottom, multiplier:1.0, constant:0.0)
let leftConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Left, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Left, multiplier:1.0, constant:0.0)
let rightConstraint = NSLayoutConstraint(item: backgroundMask!, attribute:NSLayoutAttribute.Right, relatedBy:NSLayoutRelation.Equal, toItem:superview, attribute:NSLayoutAttribute.Right, multiplier:1.0, constant:0.0)
superview?.insertSubview(backgroundMask!, belowSubview: self)
superview?.addConstraint(topConstraint)
superview?.addConstraint(bottomConstraint)
superview?.addConstraint(leftConstraint)
superview?.addConstraint(rightConstraint)
}