想通了,所以我会在未来帮助任何人解决这个问题。将您的 .maximumSize
设置为您的首选尺寸。然后设置窗口后,再次使用DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
设置.maximumSize
,但是这次你要的是实际的最大窗口大小。
我的完整代码:
func scene(_ scene: UIScene,willConnectTo session: UISceneSession,options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
#if targetEnvironment(macCatalyst)
let toolbarDelegate = NewSchoolworkToolbar()
let toolbar = NSToolbar(identifier: "main")
windowScene.title = "New Schoolwork"
if let titlebar = windowScene.titlebar {
titlebar.toolbar = toolbar
titlebar.toolbarStyle = .unified
titlebar.separatorStyle = .shadow
}
#endif
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
let newClassworkView = NewClassworkTableViewController()
windowScene.sizeRestrictions?.minimumSize = CGSize(width: 400,height: 500)
// This will be your "preferred size"
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 500,height: 800)
window.rootViewController = newClassworkView
self.window = window
window.makeKeyAndVisible()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// This will be your actual size.
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 9000,height: 9000)
}
}
本文链接:https://www.f2er.com/336.html