如何解决iOS 13 后的外部显示器
在 iOS 13 中,screen
的 setter 已被弃用,并且没有太多文档说明替代方案应该是什么。我查看了其他堆栈溢出帖子,例如 this one,但代码在我的应用中不起作用。这是我在视图控制器中设置外部显示器的功能,该功能有效,但警告我 setter 已被弃用用于屏幕。它在我的 ViewController 的 viewDidLoad()
函数中调用。
在我的 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
}
}
什么取代了这个 setter,我需要如何更新代码才能使其工作?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。