我试图将子视图添加到应用的keyWindow
,并使用自动布局进行定位。但是,自动布局似乎不起作用,而设置一个帧却行。我想我的观点infoSc
对齐到keyWindow
的使用下面的代码底部:在视图中使用自动布局添加到UIWindow
let infoSc = InfoScreenView()
infoSc.translatesAutoresizingMaskIntoConstraints = false
let keyWindow = UIApplication.sharedApplication().keyWindow!
keyWindow.addSubview(infoSc)
keyWindow.addConstraint(NSLayoutConstraint(item: infoSc, attribute: .Left, relatedBy: .Equal, toItem: keyWindow, attribute: .Left, multiplier: 1, constant: 0))
keyWindow.addConstraint(NSLayoutConstraint(item: infoSc, attribute: .Right, relatedBy: .Equal, toItem: keyWindow, attribute: .Right, multiplier: 1, constant: 0))
keyWindow.addConstraint(NSLayoutConstraint(item: infoSc, attribute: .Bottom, relatedBy: .Equal, toItem: keyWindow, attribute: .Bottom, multiplier: 1, constant: 0))
infoSc.addConstraint(NSLayoutConstraint(item: infoSc, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 100))
但是,它似乎有使用这种方法的CGRectZero
的框架。任何想法如何使这项工作?理想情况下,我也想将它与self.view
中的内容对齐,但会引发self.view
不在keyWindow
的视图层次结构中的错误。
显示完整的错误 – anders