UIApplication在swift3 Xcode8中没有成员keywindow

时间:2016-11-16 19:10:09

标签: swift3 xcode8 uiapplication

我在xcode8中编写此代码,但我有错误:

Missing required parameters for [Route: resource] [URI: resource/{Resource_ID}])

但我有错误,UIApplication没有成员keywindow

我该怎么做!?

2 个答案:

答案 0 :(得分:0)

经过大量搜索后我发现它如何解决:

if let window = UIApplication.shared.delegate?.window {
            let blackView = UIView()
            blackView.backgroundColor = UIColor.black
            window?.addSubview(blackView)
            blackView.frame = (window?.frame)!

        }

SOLVE:

  

shared.delegate.window

而不是

  

sharedApplication.keywindow

blackView.frame = window.frame

将其更改为

blackView.frame = (window?.frame)!

答案 1 :(得分:0)

解决:(斯威夫特3)

if let window = UIApplication.shared.keyWindow {
            let blackView = UIView()
            blackView.backgroundColor = UIColor.black

            window.addSubview(blackView)
            blackView.frame = window.frame
}