I'm trying to require a minimum size in my UIKit-based iOS app. I added code to set that using the UIWindowScene.sizeRestrictions property to my app's scene delegate as recommended in Apple's documentation:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let currentScene = (scene as? UIWindowScene) else { return }
currentScene.sizeRestrictions?.minimumSize.height = 400
currentScene.sizeRestrictions?.minimumSize.width = 320
print("*** Size restrictions: \(String(describing: currentScene.sizeRestrictions))")
...
}
When I run that in the simulator for an iOS 27 iPhone, the size restrictions property prints out as being nil. That's surprising to me, since the documentation states that "The system provides this object only when it supports variable-sized windows.", and iPhone windows are resizable in iOS 27.
If this is working as expected, is there another way to restrict the size of an iPhone window in iOS 27?
Hi @dsbirch, thanks for mentioning me. We do receive those mentions, despite the tag not looking like it worked.
I want to be able to enforce a minimum size for my app's window when it's being resized.
You can’t prevent users from resizing the simulator, the iPhone mirroring window, or an iPad app if multitasking mode is enabled. Which means you must be aware what your app will look like when resized. Being that's the case, SwiftUI views will expand to fill the available space automatically, UIKit views don't do this on their own. UIKit views are frame and Auto Layout based, so a view won't adapt when the window resizes unless you have constraints that account for the new size, or you handle it yourself.
If that's the case, is there a way to test for setting sizing limits?
The UISceneSizeRestrictions documentation confirmed that is the case:
The system provides this object only when it supports variable-sized windows.
You should be able to toggle Resize Mode after running your app. If this is not the case, please file a bug report using Feedback Assistant.
I hope this information is helpful.
Travis