简体   繁体   中英

How to close a Full-Screen mode NSWindow programmatically?

My application has two windows(main and video) and both can enter the Full-Screen mode independently. And the main window has a button to toggle the video window's visibility. When the video window is visible, the button simply sends close message like this:

[theVideoWindow close];

It works perfectly when the video window is not in the Full-Screen mode.

But when the video window is running in the Full-Screen mode, the window looks like being ordered out (closed), but it is still alive (like an invisible window) and accepts mouse event. The user cannot interact with other applications because the invisible window eats up all the mouse events and cannot close it because the title bar and menu are gone.

Are there any best practices to close a Full-Screen mode window programmatically other than exiting from the Full-Screen mode first and then closing it in NSWindowDidExitFullScreenNotification notification handler?

Thanks in advance.


It seems to be my mistake. The other developer, explicitly send orderFront: in the NSWindowDidExitFullScreenNotification notification handler to make the window visible just after exiting from the Full-Screen mode and it made the window was still alive.

On my app, I check if window is on Fullscreen and then I use ToogleFullScreen method

- (BOOL)isFullScreen {
     return ((self.window.styleMask & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}

if([self isFullscreen]) {
     [self.window toggleFullScreen:nil];
}

@Saul's solution in Swift 4:

func isFullScreen() -> Bool {
    guard let window = view.window else { return false }
    return window.styleMask.contains(.fullScreen)
}

if isFullscreen() {
    view.window?.toggleFullScreen(nil)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM