keyDown not being called

后端 未结 2 693
误落风尘
误落风尘 2020-12-10 17:39

I have a custom NSView called SurfaceView. It is the contentView of a NSWindow and it handles basic events like mouse click and drawing. But don\'t matters what I do, it doe

相关标签:
2条回答
  • 2020-12-10 17:52

    I found out what was preventing the keyDown event from being called. It was the NSBorderlessWindowMask mask, it prevents the window from become the key and main window. So I have created a subclass of NSWindow called BorderlessWindow:

    @interface BorderlessWindow : NSWindow
    {
    }
    
    @end
    
    @implementation BorderlessWindow
    
    - (BOOL)canBecomeKeyWindow
    {
        return YES;
    }
    
    - (BOOL)canBecomeMainWindow
    {
        return YES;
    }
    
    @end
    
    0 讨论(0)
  • 2020-12-10 17:59

    In addition to answer: Check in your IB checkbox for NSWindow.

    Title Bar should be checked. It the similar to NSBorderlessWindowMask

    enter image description here

    0 讨论(0)
提交回复
热议问题