简体   繁体   中英

How to partially disable resize properties of NSWindow?

在此处输入图像描述

In one of my NSWindow (shown in above image) I want to disable split window properties ie "Tile Window to Left of Screen" & "Tile Window to Right of Screen".

My existing Window Controller code is provide below:

class VideoWindowController: NSWindowController, NSWindowDelegate {

    override func windowDidLoad() {
        super.windowDidLoad()

        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.

        self.window?.titlebarAppearsTransparent = false
        self.window?.backgroundColor = NSColor.init(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
        self.window?.styleMask = NSWindow.StyleMask(rawValue: NSWindow.StyleMask.resizable.rawValue | NSWindow.StyleMask.titled.rawValue | NSWindow.StyleMask.closable.rawValue |  NSWindow.StyleMask.miniaturizable.rawValue)            
    }

    @objc func setNonResizableStyle() {
        self.window?.titlebarAppearsTransparent = false
        self.window?.styleMask = NSWindow.StyleMask(rawValue: NSWindow.StyleMask.titled.rawValue | NSWindow.StyleMask.miniaturizable.rawValue)
        self.window?.level = .floating
    }

    @objc func setResizableStyle() {
        self.window?.titlebarAppearsTransparent = false
           self.window?.styleMask = NSWindow.StyleMask(rawValue: NSWindow.StyleMask.resizable.rawValue | NSWindow.StyleMask.titled.rawValue | NSWindow.StyleMask.closable.rawValue |  NSWindow.StyleMask.miniaturizable.rawValue)
        self.window?.level = .normal

       }
}

You must change the collectionBehavior of your NSWindow object to disable certain split window features:

window?.collectionBehavior = [.fullScreenDisallowsTiling]

More info can be found here: https://developer.apple.com/documentation/appkit/nswindow/collectionbehavior

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM