【发布时间】:2020-07-26 04:53:11
【问题描述】:
我试图按照本教程创建一个多屏应用程序:
https://www.youtube.com/watch?v=UYviLiI2rlY&t=774s
不幸的是,在 25:00 - 26:00 分钟,我收到一条错误消息,并且我的外部屏幕一直黑屏:
[Assert] Error in UIKit client: -[UIWindow setScreen:] should not be called if the client adopts
UIScene lifecycle. Call -[UIWindow setWindowScene:] instead.
我的代码是:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
var additionalWindows = [UIWindow]()
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(forName: UIScreen.didConnectNotification, object: nil, queue: nil) { [weak self] notification in
guard let self = self else {return}
guard let newScreen = notification.object as? UIScreen else {return}
let screenDimensions = newScreen.bounds
let newWindow = UIWindow(frame: screenDimensions)
newWindow.screen = newScreen
guard let vc = self.storyboard?.instantiateViewController(withIdentifier: "PreviewViewController") as? PreviewViewController else {
fatalError("Unable to find PreviewViewController")
}
newWindow.rootViewController = vc
newWindow.isHidden = false
self.additionalWindows.append(newWindow)
}
}
}
我在newWindow.screen = newScreen : Setter for 'screen' was deprecated in iOS 13.0 中有一个弃用警报,但我找不到任何有用的东西,而且对于如何解决这个问题也不过分复杂。
【问题讨论】:
-
苹果干得好。他们弃用了命令,但他们的文档仍然提到使用屏幕设置器 [developer.apple.com/documentation/uikit/windows_and_screens/… 关于如何设置屏幕属性的任何进展?
-
不,我的项目被搁置了......
-
这里有一些相关信息,虽然是为 SWIFTUI 准备的。没有太多时间去看看。如果您想看一下,这是链接。 [stackoverflow.com/questions/58033818/…
标签: ios swift ios13 uiwindow uiwindowscene