Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable the window resizing feature on my Mac Catalyst iOS app

I'm migrating my iOS app to support MacCatalyst but I'd like to prevent the window from being resized by the user.

Do you have any tips for that?

like image 547
marcelosalloum Avatar asked Dec 17 '22 16:12

marcelosalloum


1 Answers

Since Xcode11 Beta 5, the UIWindowScene class started supporting the property sizeRestrictions.

If you set sizeRestrictions.maximumSize and sizeRestrictions.minimumSize to the same value, the window will not be resizable. To do so, just call this in your application:didFinishLaunchingWithOptions method (if you're using UIKit):

    UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.forEach { windowScene in
        windowScene.sizeRestrictions?.minimumSize = CGSize(width: 480, height: 640)
        windowScene.sizeRestrictions?.maximumSize = CGSize(width: 480, height: 640)
    }

If you're using SwiftUI instead of UIKit, you should actually add it to scene(_:willConnectTo:options:) in your scene delegate.

Note: You need to run this in OSX 10.15 Beta 5 or later, otherwise it will crash

like image 143
marcelosalloum Avatar answered Jan 30 '23 07:01

marcelosalloum