In MacCatalyst,Setting the view size of UIWindow will cause viewDidLayoutSubviews not to be called when UIViewController resizer the edge of the drag window

macOS Monterey 12.6,MacBook Pro (16-inch, 2019)

MacCatalyst App, version support macOS 15

code:

let mainWindow = UIWindow.init(windowScene: windowSence)

mainWindow.frame = frame // Settings can cause bugs

mainWindow.rootViewController = ***

Setting the view frame of UIWindow will cause viewDidLayoutSubviews not to be called when UIViewController resizer the edge of the drag window

I expect to be able to set the initial size of the window when I open it, if I have any problems with the way I use it, please help provide the appropriate way to call it

Answered by lixuan985589477 in 760683022

if #available(macCatalyst 16.0, *) { let geometryPreferences = UIWindowScene.GeometryPreferences.Mac(systemFrame: frame) windowScene.requestGeometryUpdate(geometryPreferences) { error in

    }

}

A solution has been found

On the Mac the closest equivalent of a UIWindowScene is an NSWindow (the native window object of AppKit) – UIWindow is conceptually a subview of the NSWindow. As such changing the size of the UIWindow does not control the size of the scene, and for compatibility reasons takes you off the path where the window is automatically sized to fill its scene.

You can use UIWindowScene.sizeRestrictions to reflect some customization of the window sizing, but I don't recall if there is a more direct means to do what you want.

Accepted Answer

if #available(macCatalyst 16.0, *) { let geometryPreferences = UIWindowScene.GeometryPreferences.Mac(systemFrame: frame) windowScene.requestGeometryUpdate(geometryPreferences) { error in

    }

}

A solution has been found

In MacCatalyst,Setting the view size of UIWindow will cause viewDidLayoutSubviews not to be called when UIViewController resizer the edge of the drag window
 
 
Q