How to change the NSScreen a NSWindow appears on

后端 未结 2 1935
梦如初夏
梦如初夏 2021-01-14 17:36

I have an application that will load a couple of windows depending on which button is pressed. All except one of these open on the mainScreen (the screen in which the main w

相关标签:
2条回答
  • 2021-01-14 18:13

    I could not get toohtik's answer to work. What I ended up doing was subclassing NSWindow and then overriding constrainFrameRect: toScreen:. This will automatically open the new window on the "main screen" of the application.

    - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
    {
        AppDelegate *delegate = [[NSApplication sharedApplication] delegate];
        return [super constrainFrameRect:frameRect toScreen:delegate.window.screen];
    }
    
    0 讨论(0)
  • 2021-01-14 18:22

    I dont't know why you have that behaviour but you can change it through initWithFrame method that takes NSScreen argument.

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