NSToolbar is displayed when you enter full screen mode

I am developing an application in which a toolbar can be displayed / hidden by the user with a button. The problem is this: If the user chooses to hide the toolbar and then enters full-screen mode, the toolbar is displayed.

The user interface was created programmatically (i.e. does not use Interface Builder).

This is creating a toolbar in an application 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 tried to fix this using the window’s delegate methods, but still the toolbar is displayed when I enter full screen mode regardless of the editing value.

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

}

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

}

Thank you very much in advance!

+4
source share
1 answer

I could not find a way to maintain the hidden / displayed state of the toolbar when the window goes out of full screen mode, but you can set the toolbar to always be hidden in full screen mode and animate when the user goes to the top of the screen. In your window delegate, you can set NSApplicationPresentationOptions to return NSApplicationPresentationAutoHideToolbar as one of the parameters. My 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

+9
source

Source: https://habr.com/ru/post/1396231/


All Articles