Show application on multiple screens - macos

I have an Application which should be shown on multiple screens simultaneously. With the main screen is not a problem, but it does not work for the second screen

I have found the solution, just retrieve frame of the second screen and show window in main screen but using the frame of the second screen
NSRect secScreenRect = [secondScreen frame];
myWindow = [[NSWindow alloc] initWithContentRect:secScreenRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:[NSScreen mainScreen]];
...

Related

Display NSWindow on secondary screen

I would like to display an NSWindow created in a storyboard full screen on a secondary monitor. The below code results in the window being displayed on the primary screen/main screen. The Y origin is ok but the X origin is 0 where it should be -1680. The code below worked before Yosemite.
NSScreen *screen = [[NSScreen screens] objectAtIndex:2];
NSRect mainDisplayRect = [screen frame];
[PresenterWindow setFrame: mainDisplayRect display:YES animate:YES];
[PresenterWindow makeKeyAndOrderFront:sender];
[PresenterWindow setLevel: CGShieldingWindowLevel()];
I had also tried the following with the same result:
[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, [screen frame].size.width, [screen frame].size.height)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:screen];
Please advise how I can fix this.
I've tried solutions from some other questions:
Cocoa Open a fullscreen window on the second screen maintaining the app visible on the first - did not work - same result.
Display os x window full screen on secondary monitor using Cocoa - nope - neither with enterFullScreenMode:withOptions: method of NSView.
I have some new observations:
If i activate the "Launch At Startup" in the storyboard for my NSWindow the window is viewed fullscreen on my secondary monitor. If i then do a orderOut and run the above code the window is viewed in correct size but on my primary/main screen. The window is not activated to "Release When Close". So when I deactivate "Launch At Startup" the window is again viewed in the primary/main screen with the size of the secondary screen.
After some days I got it to work:
The NSWindow in the storyboard was marked with "Launch At Startup"
In the applcationDidFinishLaunching i wrote the following:
[PresenterWindow setLevel: NSNormalWindowLevel];
[PresenterWindow orderOut:self];
To open full screen I used this:
NSScreen *screen = [[NSScreen screens] objectAtIndex:1];
NSRect mainDisplayRect = [screen frame];
[PresenterWindow setFrame: mainDisplayRect display:YES animate:YES];
[PresenterWindow setLevel: CGShieldingWindowLevel()];
[PresenterWindow makeKeyAndOrderFront:screen];
To close full screen and to be able to open full screen again correctly:
[PresenterWindow setLevel: NSNormalWindowLevel];
[PresenterWindow orderOut:(sender)];

How UIToolbarPosition is handled by UIToolbar?

I'm using setBackgroundImage:forToolbarPosition:metrics: method of UIToolbar.
That's my code:
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, 320, 44)];
[toolbar setBackgroundImage:[UIImage imageNamed:#"top"] forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsDefault];
[toolbar setBackgroundImage:[UIImage imageNamed:#"bottom"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];
[self.view addSubview:toolbar];
As you can see I've put my toolbar on top. However when I run the code the toolbar image used is [UIImage imageNamed:#"bottom"].
How UIToolbarPosition is obtained?
My first idea is frame check ( < 1/2 superview frame is top, otherwise is bottom... or sort of).
It still on bottom. Any idea?
on iPhone UIToolbarPosition is always on bottom because UIToolbar is not supposed to be on top.
on iPad it works fine, UIToolbarPositionTop is used when toolbar.frame.origin.y = 0, UIToolbarPositionBottom otherwise.

UISplitView crashing after selecting a row

I have a UISPlitViewController, I have a UITableView in my rootView and have a detailView, on select of second row in my rootView, what i am trying to do is: remove the UISplitViewController and add a new UISplitViewController (based on my requirement), so in the portrait mode when i select second row from the popOver, the application crashing? (but works well in landscape mode).
I'm 100% sure I can answer the question, but it would help if you posted some code. What code are you using now that is working for landscape but crashes in portrait?
(I would've written this in a comment, but I need 50 rep for that).
[splitViewController.view removeFromSuperview];
splitViewController = [[UISplitViewController alloc] init];
rootObj = [[HotelsRootViewController alloc] init];
mapObj = [[mapViewController alloc] init];
rootObj.mapObj = mapObj;
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootObj];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:mapObj];
[mapObj release];
splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
splitViewController.delegate=mapObj;
[window addSubview:splitViewController.view];
[window makeKeyAndVisible];
This is what i do on selection of the second row in my rootViewController, im removing the entire splitView and adding a new SplitView (based on my requirement), but if im in landscape mode, the app doesnt crash, when i turn my iPad in Potrait mode, when i click the button in the toolbar and in the popOver when i select the same second row in the rootView, the app is crashing.....hope u understood now....

How to avoid double window opening at launch?

I've been porting my cocos2D iOS game to Mac and it works without problems but I don't understand why I get two windows open every time I launch the app.
One of them is the cocos2d window with the main menu scene and the properties and name I give but there is another blank white window with the app name (I mean the Xcode project name). I suppose this is a trivial issue but I really can't avoid that window from appearing.
What am I doing wrong?
This is my AppDelegate window initialization:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
//Posiciona ventana y define escalado
NSRect aFrame=[[NSScreen mainScreen] frame];
CGSize winSize = CGSizeMake(1024,768);
CC_DIRECTOR_INIT(winSize);
[self.window showsResizeIndicator];
[director setResizeMode:kCCDirectorResize_AutoScale];
[director setProjection:kCCDirectorProjection2D];
[window_ setContentAspectRatio:NSMakeSize(winSize.width,winSize.height)];
[window_ setStyleMask:[window_ styleMask] | NSResizableWindowMask | NSMiniaturizableWindowMask];
[window_ setTitle:#"Barman Hero"];
aFrame=[[NSScreen mainScreen] frame];
if (aFrame.size.width<=winSize.width || aFrame.size.height<=winSize.height) [window_ zoom:self];
[window_ center];
[glView_ setFrameSize:NSMakeSize(window_.frame.size.width,window_.frame.size.height-22)];
// Enable "moving" mouse event. Default no.
[window_ setAcceptsMouseMovedEvents:NO];
.....
.....
.....
//Carga escena principal
[[CCDirectorMac sharedDirector] runWithScene:[MainMenu scene]];
}
Thanks in advance.
It is likely that you have a Window defined in MainMenu.xib that is being opened semi-automatically. Remove the window from MainMenu.xib and any code that might reference it and it should no longer open the second window.

NSWindow problem

Please help me. I set frame to the window like this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
[window makeKeyWindow];
[window setFrame:NSMakeRect(0, 0, 1024, 768) display:YES];
[window setBackgroundColor:[NSColor clearColor]];
[window center];
}
But real window size: width = 1024, height = 620. I think because my screen size (1280x720).
So, when [window setContentView:myView], myView is disable a part.
I can't solve this problem. Please help me solve this.
Thanks.
Size your content view to fit the space available using -[NSWindow contentRectForFrameRect:]. You should also consider sizing your window's frame to fit the available space, as well, such as by using -[NSScreen visibleFrame]. Both the Dock and the menu bar eat some space, so you should not expect to have the full screen size available to your application.
If you want to show your window at the maximum size, have a look at NSWindow's -zoom: method

Resources