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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With