Xcode 11 - Disable Resize Mode in Catalyst Swift

Xcode 11 - Disable resize mode in catalyst swift

Beta 5 added a sizeRestrictions property to UIWindowScene.

If you set sizeRestrictions.maximumSize and sizeRestrictions.minimumSize to the same value, the window will not be resizable:

windowScene.sizeRestrictions?.minimumSize = CGSize(width: 640, height: 480)
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 640, height: 480)

The easiest place to add this code is probably scene(_:willConnectTo:options:) in your scene delegate. The scene object passed in is a UIWindowScene, so just cast it and then set sizeRestrictions.

Note: sizeRestrictions are only available in iOS 10.15 Beta 5. This code will crash in older betas.

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

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

How to detect window resizing in Mac Catalyst?

Just like in iOS. Use windowScene(_:didUpdate:interfaceOrientation:traitCollection:) in your window scene delegate, or implement viewWillTransition(to:with:) in your view controllers.

Allow resize on Designed for iPad App for Apple Silicon Mac

Ok, I figured it out on my own. If you want to enable the screen resizing, you have to disable "Requires full screen" on the project settings and enable all the orientations. That, unfortunately, let the App on iPad be able to be splitted (1/3, 1/2, 2/3) so you have to adapt the interface.

Sample Image

I don't think it's possibile to keep these two features separated, but it makes sense because if you want your App to be resizable, you have to do all the interfaces adjustments that you would need as well on the iPad for all the size classes.

Mac-catalyst - minimum window size for Mac catalyst app

Just add the following chunk of code to your application:didFinishLaunchingWithOptions method (for UIKit projects) or to scene(_:willConnectTo:options:) (for SwiftUI projects):

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

PS: you can also set the maximumSize property there

PS2: If you set both minimumSize and maximumSize to the same value, the window size will remain static and won't be resizable.



Related Topics



Leave a reply



Submit