Create a window at the top of the application

In my application, I have a set of windows. I need some of the windows to be the largest when the application is active. I tried to do this by changing the window level but not getting

If I put NSNormalWindowLevel, then when I click on any other window of my application, this window will be in the background. If I use any other level than NSNormalWindowLevel, then the window remains the topmost, even if I switch to another application. I want the window to be the top only when my application is active. How to do it in cocoa?

thank

+3
source share
4 answers

, , NSWindow, , setHidesonDeactivate NSFloatingWindowLevel .

+4

, ( Interface Builder):

,

[window setLevel: NSMainMenuWindowLevel];

(NSWindowController),

[windowController showWindow:self];
[windowController.window setLevel: NSMainMenuWindowLevel];

:

NSNormalWindowLevel       
NSFloatingWindowLevel   
NSSubmenuWindowLevel    
NSTornOffMenuWindowLevel
NSMainMenuWindowLevel   
NSStatusWindowLevel      
NSDockWindowLevel        
NSModalPanelWindowLevel   
NSPopUpMenuWindowLevel    
NSScreenSaverWindowLevel 

Interfacebuilder (.. ), IBAction App- :

-(IBAction)showWindowCalledFromMenu:(id)sender {

   [self.window setLevel: NSMainMenuWindowLevel];
   [self.window makeKeyAndOrderFront:self];
}

, , , , . "main.xib" "" "First Responder". reset : "deminiaturize", "order Front", "order Back" .

, . !

+5

OS X , " ". . , , , , (. NSPanel setFloatingPanel:). .

0

/ ( deovrat singh )

-(void) windowDidLoad {
    [super windowDidLoad];
    [self.window setLevel: NSFloatingWindowLevel];
    [self.window setHidesonDeactivate:YES];

    //....
}
0

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


All Articles