Xcode 11 - Disable resize mode in catalyst swift

女生的网名这么多〃 提交于 2019-12-07 01:15:15

问题


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?


回答1:


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.




回答2:


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)
    }


来源:https://stackoverflow.com/questions/57388389/xcode-11-disable-resize-mode-in-catalyst-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!