We are converting our Swift based iOS app to Mac compatible using Catalyst in Xcode 11.
We are facing an issue in UI when user resize app window. So can we disable resize mode and give fix frame for app window?
We are converting our Swift based iOS app to Mac compatible using Catalyst in Xcode 11.
We are facing an issue in UI when user resize app window. So can we disable resize mode and give fix frame for app window?
On
You can call this in your application:didFinishLaunchingWithOptions method:
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)
}
On
for Objective-C try
#if TARGET_OS_MACCATALYST
for (UIScene* scene in UIApplication.sharedApplication.connectedScenes) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene* windowScene = (UIWindowScene*) scene;
windowScene.sizeRestrictions.minimumSize = CGSizeMake(480, 640);
}
}
#endif
Beta 5 added a
sizeRestrictionsproperty to UIWindowScene.If you set
sizeRestrictions.maximumSizeandsizeRestrictions.minimumSizeto the same value, the window will not be resizable:The easiest place to add this code is probably
scene(_:willConnectTo:options:)in your scene delegate. Thesceneobject passed in is aUIWindowScene, so just cast it and then setsizeRestrictions.Note:
sizeRestrictionsare only available in iOS 10.15 Beta 5. This code will crash in older betas.