All methods of directly reusing controllers are incredibly powerful and must be mastered.

🌰 🌰 : / / the pop-up NSViewController func showSheetController () {let controller = NNBatchClassCreateController () let the rect = CGRectMake(0, 0, kScreenWidth*0.25, kScreenHeight*0.25) nswindow. show(with: controller, size: Rect. size) {(response) in DDLog(response)}} //NSViewController close popover: nswindow.end (with: self, response: NSApplication.ModalResponse.OK)Copy the code

Source:

@objc public extension NSWindow {static var defaultRect: CGRect {return CGRectMake(0, 0, kScreenWidth*0.4, kScreenHeight*0.5)} static func create(_ rect: CGRect = NSWindow.defaultRect, title: String = NSApplication.appName) -> Self { // let style = NSWindow.StyleMask.titled.rawValue | NSWindow.StyleMask.closable.rawValue | NSWindow.StyleMask.miniaturizable.rawValue | NSWindow.StyleMask.resizable.rawValue let style: NSWindow.StyleMask = [.titled, .closable, .miniaturizable, .resizable] let window = self.init(contentRect: rect, styleMask: style, backing: .buffered, defer: false) window.title = title window.titlebarAppearsTransparent = true return window; } static func create(_ rect: CGRect = NSWindow.defaultRect, controller: NSViewController) -> Self { let window = Self.create(rect, title: controller.title ?? "") window.contentViewController = controller; return window; } static func createMain(_ rect: CGRect = NSWindow.defaultRect, title: String = NSApplication.appName) -> Self { let window = Self.create(rect, title: title) window.contentMinSize = window.frame.size; window.makeKeyAndOrderFront(self) window.center() return window; } static func show(with controller: NSViewController, size: CGSize, handler: ((NSApplication.ModalResponse) -> Void)? = nil) { controller.preferredContentSize = size let rect = CGRectMake(0, 0, size.width, size.height) let panel = Self.create(rect, controller: controller) NSApp.mainWindow? .beginsheet (panel, completionHandler: handler)} /// Drop down popover close static func end(with controller: NSViewController, response: NSApplication.ModalResponse) { guard let window = controller.view.window else { return } if window.isMember(of: Self.classForCoder()) == true { // view.window? .orderOut(self) NSApp.mainWindow? .endSheet(window, returnCode: response) } } }Copy the code