xcodeswiftnswindownstextfieldkeywindow

NSBorderlessWindowMask Subview NSTextfield not keybard editable Swift


I'm using a NSBorderlessWindowMask for my main window on a Swift project (without storyboards), when I load a Subview, the NSTextfield outlet is not keybard editable. I already put this code on the initialisation:

self.window?.makeKeyWindow()
self.window?.becomeKeyWindow()

this allows the outlet to be "blue" like on focus, but the keyboard editing is disabled, i can copy/paste on the textfield


Solution

  • I found an awesome workaround for this problem: basically setup at beginning the NSWindow mask as NSTitledWindowMask, when application is loaded, remove set up the new mask NSBorderlessWindowMask

       func applicationWillFinishLaunching(notification: NSNotification) {
            self.window?.titleVisibility = NSWindowTitleVisibility.Hidden
            self.window?.styleMask = NSTitledWindowMask // adds title bar
        }
    
        func applicationDidFinishLaunching(aNotification: NSNotification) {
    
            self.window?.makeKeyWindow()
            self.window?.becomeKeyWindow()
            self.window.setIsVisible(true)
            self.window?.styleMask = NSBorderlessWindowMask // removes title bar
        }