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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With