2015-02-05 131 views
0

我開始使用自動佈局,並且我的UIViewController的self.view不再佔用iPhone 6或iPhone 6plus的整個屏幕。 UIView的大小是size =推斷的。使用自動佈局使UIView全屏

我已經查看了我的VC的主視圖的約束條件,並且約束編輯器不讓我選擇我想要的距離爲0,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) 

}