我試圖將子視圖添加到應用的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