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.
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
Read and Write CSV Files in Swift 3
Nssortdescriptor Sorting Using Nsdate in Swift
Using 'If-Case' Format in Boolean Assignment in Swift
Is .Playground a Swift File? Who Can 'See' It
Alamofire Returns Wrong Encoding
Timer Not Firing Every Second on Watchkit
Swift 2 Error Handling and While
How to Add a Loading View for Apple Watch
Why Does This Swiftui Picker Code Not Work
Swift Sprite Kit in App Purchase
Mfmailcomposeviewcontroller Error [Mc] Filtering Mail Sheet Accounts for Bundle Id
How to Set the iOS13 Uisegmentedcontrol Backgroundcolor to White
Modifying an Array Passed as an Argument to a Function in Swift
Avplayer Seektotime Not Working Properly
Argument of '#Selector' Does Not Refer to an '@Objc' Method, Property or Initializer