我试图按照本教程创建一个多屏应用程序:
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
但我找不到任何有用的东西,而且对于如何解决这个问题也没有过于复杂。