I'm trying to port a game to macOS using Mac Catalyst. The game content doesn't dynamically resize and I'm trying to force a fixed 3:4 aspect ratio (like an iPad on portrait) at the start of the app, so I've added this to my AppDelegate class:
That works in fixing the aspect, but the window looks small in a 15-inch MacBook Pro. nativeBounds is always 1920x1080, where the native resolution should be 1920x1200. UIScreen.main gives me 1920x1080 as well.
How can I get the real size of the screen?
Code Block swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { #if targetEnvironment(macCatalyst) /* some margin */ let titleHeight: CGFloat = 34 * 4 UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.forEach { windowScene in windowScene.titlebar?.titleVisibility = .hidden /* screen seems to always be 1920x1080 ??? */ let height = windowScene.screen.nativeBounds.height - titleHeight let width = 3 * height / 4 windowScene.sizeRestrictions?.minimumSize = CGSize(width: width, height: height) windowScene.sizeRestrictions?.maximumSize = CGSize(width: width, height: height) } #endif }
That works in fixing the aspect, but the window looks small in a 15-inch MacBook Pro. nativeBounds is always 1920x1080, where the native resolution should be 1920x1200. UIScreen.main gives me 1920x1080 as well.
How can I get the real size of the screen?