iOS 13 では、setter forscreen
は廃止されました。代替手段がどうあるべきかを示すドキュメントはあまりありません。このような他のスタック オーバーフローの投稿を確認しましたが、コードがアプリで機能しません。これは、View Controller にある外部ディスプレイをセットアップする機能ですが、これは動作しますが、setter が screen に対して非推奨になっていることを警告します。viewDidLoad()
私のViewControllerの関数で呼び出されます。
ViewController で初期化された変数
// External Display Support
var secondWindow: UIWindow?
var secondScreenView: UIView?
外部画面に接続して表示する機能。
@objc func setupScreen() {
if UIScreen.screens.count > 1 {
// Find and store the second screen
let secondScreen = UIScreen.screens[1]
// Create a local variable to store the second window using the screen's dimensions
let externalWindow = UIWindow(frame: secondScreen.bounds)
// Windows require a root view controller
let viewController = UIViewController()
// Tell the window which screen to use
externalWindow.screen = secondScreen // This is where the deprecation error is
// Set the dimensions for the view for the external screen so it fills the screen
secondScreenView = UIView(frame: externalWindow.frame)
// Add the view to the window
externalWindow.addSubview(secondScreenView)
// Unhinde the window
externalWindow.isHidden = false
// Configure the View
let hostingController = HostingControllerPresentable(rootView: DefaultPresentationView(appIcon: Bundle.main.icon ?? UIImage()))
viewController.addChild(hostingController)
viewController.view.addSubview(hostingController.view)
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
hostingController.view.topAnchor.constraint(equalTo: (viewController.view.topAnchor)),
hostingController.view.bottomAnchor.constraint(equalTo: (viewController.view.bottomAnchor)),
hostingController.view.leadingAnchor.constraint(equalTo: (viewController.view.leadingAnchor)),
hostingController.view.trailingAnchor.constraint(equalTo: (viewController.view.trailingAnchor)),
])
hostingController.didMove(toParent: externalWindow.rootViewController)
secondWindow = externalWindow
externalWindow.rootViewController = viewController
}
}
このセッターを置き換えるものは何ですか?また、これを機能させるにはコードをどのように更新する必要がありますか?