添加带约束的子视图会使视图变黑

Adding subview with constraints makes view black

我正在尝试通过将此代码添加到我的 "BaseViewController" 来为我的所有视图控制器添加覆盖。然而,它会导致所有 ViewController 变黑并且行为异常。

override public func viewDidLoad()
{
    super.viewDidLoad()

    overlayView = UIView()
    overlayView.backgroundColor = UIColor.redColor() //For testing
    view.addSubviewWithMatchingConstraints(overlayView)
    ...
}

并且在 UIView 扩展中:

func addSubviewWithMatchingConstraints(subView: UIView)
{
    translatesAutoresizingMaskIntoConstraints = false
    addSubview(subView)

    addConstraint(NSLayoutConstraint(item: subView, attribute: .Width, relatedBy: .Equal, toItem: self, attribute: .Width, multiplier: 1, constant: 0))
    addConstraint(NSLayoutConstraint(item: subView, attribute: .Height, relatedBy: .Equal, toItem: self, attribute: .Height, multiplier: 1, constant: 0))
    addConstraint(NSLayoutConstraint(item: subView, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1.0, constant: 0))
    addConstraint(NSLayoutConstraint(item: subView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: 0))
}

问题是我在父项而不是子项上设置了 translatesAutoresizingMaskIntoConstraints

childView.translatesAutoresizingMaskIntoConstraints = false

已修复