I spent a great deal of time figuring out how to determine if my NSWindow is in full screen mode or not and also how to enable/disable it from going in or out of full screen mode. This is useful when I am animating a view to another view or doing something where going into or out of full screen mode will mess stuff up. Sort of like locking down a window from being resized.
The answer to this is posted below.
For anyone interested here are some methods you can categorize or use as is. I spent some time looking for how to do this and thought it can help someone else out:
This one will tell you if you are or are not in full screen mode:
@implementation MyWindow
- (void) setStyleMask:(NSUInteger)styleMask {
MyWindowController *wndController = (MyWindowController *)self.windowController;
wndController.fullScreenMode = (styleMask & NSFullScreenWindowMask);
[super setStyleMask:styleMask];
}
@end
I am setting a property in my window controller.
For completeness here is what the category on NSWindow would look like:
@implementation NSWindow (CategoryNSWindow)
#pragma mark - Full Screen Mode:
- (BOOL) inFullScreenMode {
return (self.styleMask & NSFullScreenWindowMask);
}
@end
These two methods will enable / disable the ability to go into or out of full screen mode:
- (void) enableFullScreen {
NSWindowCollectionBehavior behavior = [self.window collectionBehavior];
behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
[self.window setCollectionBehavior:behavior];
}
- (void) disableFullScreen {
NSWindowCollectionBehavior behavior = [self.window collectionBehavior];
behavior ^= NSWindowCollectionBehaviorFullScreenPrimary;
[self.window setCollectionBehavior:behavior];
}
Rename methods as you please.
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