gpt4 book ai didi

swift - 我想在 Swift 项目中创建一个新的 UIWindow,但是出了问题

转载 作者:行者123 更新时间:2023-11-30 13:44:57 25 4
gpt4 key购买 nike

我在 Swift 中创建一个新项目,我想创建一个新的 UIWindow,这是我的 Controller 中的代码:

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let myWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
myWindow.backgroundColor = UIColor.redColor()
myWindow.hidden = false


}

当我运行该项目时,我收到消息:“应用程序窗口预计在应用程序启动结束时有一个 Root View Controller ”。但在 Objective-C 项目中,这是可以的。

谁能告诉我我的项目出了什么问题?

谢谢。

最佳答案

最后,我自己得到了答案。加载新的ViewController时不能同时创建新的UIWindow,但可以在 View 加载后创建。代码如下:

    let myWindow = {Void->UIWindow in
let cWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
cWindow.backgroundColor = UIColor.redColor()
return cWindow
}()

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

myWindow.hidden = false
}

关于swift - 我想在 Swift 项目中创建一个新的 UIWindow,但是出了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com