I'm developing an app on OSX 10.7 and I'm trying and the goal is to open some images on a second screen while the app has to run normally on the first.
So the code is the following:
NSScreen *screen = [[NSScreen screens] objectAtIndex:1];
fullScreenWindow = [[NSWindow alloc] initWithContentRect:[screenFrame]
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:screen];
[fullScreenWindow setLevel: NSMainMenuWIndowLevel + 1];
[fullScreenWindow setOpaque: YES];
[fullScreenWindow setBackgroundColor:[NSColor yellowColor]];
fullScreenView = [[NSView alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, fullScreenWindow.frame.size.width, fullScreenWindow.frame.size.height)];
// Adding a test button
NSButton *testButton = [[NSButton alloc] initWithFrame(50.0f, 50.0f, 100.0f, 50.0f)];
[testButton setTarget:self];
[testButton setAction:@selector(closeExternalWindow)];
[fullScreenView addSubview:testButton];
// Present the fullscreen window
[fullScreenWindow.contentView addSubview:fullScreenView];
[fullScreenWindow makeKeyAndOrderFront:self];
In this way, on the first screen the app is correctly shown, but on the second screen I just see a fullscreen black window.
What's the issue?
Thanks!
Reading Apple's docs for
initWithContentRect:styleMask:backing:defer:screen:
it states that the screen parameter..So when using
[screen frame]
you're actually moving it off the second screen as the positioning is relative to that screen already.In order to make it appear where expected you can change the code e.g. to
After some days I have had the possibility to work again on this code and now it works:
Jay thank you for the support ;)