How to change the NSScreen a NSWindow appears on

后端 未结 2 1937
梦如初夏
梦如初夏 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];
    }
    

提交回复
热议问题