How to change the NSScreen a NSWindow appears on

萝らか妹 提交于 2019-11-30 23:38:49

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];
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!