How to set min/max window size for mac app on catalyst

Add following four lines of code to “SceneDelegate.swift” in your project.

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let _ = (scene as? UIWindowScene) else { return }
        
// #### add following four lines of code.
        #if targetEnvironment(macCatalyst)
        window?.windowScene?.sizeRestrictions?.minimumSize = CGSize(width: 400, height: 400)
        window?.windowScene?.sizeRestrictions?.maximumSize = CGSize(width: 1280, height: 1000)
        #endif
// ### end of code
    }
...

投稿者: admin

Free Software Engineer

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です