Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSToolbar shown when entering fullscreenmode

I am developing an app in which the toolbar can be shown/hide by the user using a button. The problem is the following: If the user chooses to hide the toolbar and then enters the fullscreen mode, the toolbar is shown.

The user interface has been created programmatically (i.e. not using Interface Builder).

This is the toolbar creation in the app delegate:

mainToolbar = [[NSToolbar alloc] initWithIdentifier:MAIN_TOOLBAR];
[mainToolbar setAllowsUserCustomization:NO];
[mainToolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
[mainToolbar setDelegate:self];
[window setToolbar: mainToolbar];

These are the actions performed by the buttons:

-(void)hideToolbar {
    editing = YES;
    [mainToolbar setVisible:NO];
}

-(void)showToolbar {
    editing = NO;
    [mainToolbar setVisible:YES];
}

I have tried to fix it using window delegate methods but still the toolbar is shown when entering full screen mode regardless the value of editing.

- (void)windowDidEnterFullScreen:(NSNotification *)notification {
  [mainToolbar setVisible:!editing];

}

- (void)windowDidExitFullScreen:(NSNotification *)notification {
 [mainToolbar setVisible:!editing];

}

Many thanks in advance!

like image 269
Mariana Avatar asked Feb 13 '12 15:02

Mariana


1 Answers

I could not find a way to maintain the hidden/shown state of the toolbar when the window goes full screen, but you can set the toolbar to always be hidden in full screen, and to animate in when the user goes to the top of the screen. In your window delegate, you can set NSApplicationPresentationOptions to return NSApplicationPresentationAutoHideToolbar in as one of the options. Mine looks like this:

    - (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
    return (NSApplicationPresentationFullScreen |       
            NSApplicationPresentationHideDock |         
            NSApplicationPresentationAutoHideMenuBar |
            NSApplicationPresentationAutoHideToolbar);
}

Here is the relevant documentation: https://developer.apple.com/library/mac/#documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html

like image 153
Jon Buys Avatar answered Nov 26 '22 21:11

Jon Buys