How to bring NSWindow to front and to the current Space?

后端 未结 6 1647
闹比i
闹比i 2020-12-23 13:26

I\'m using this code to bring up my window:

[self.window makeKeyAndOrderFront:self];
[self.window setOrderedIndex:0];

But often it will be

相关标签:
6条回答
  • 2020-12-23 14:03

    Swift 3.0

    NSApp.activate(ignoringOtherApps: true)
    
    0 讨论(0)
  • 2020-12-23 14:04

    The syntax seems to be a little different with Swift 2:

    NSApplication.sharedApplication().activateIgnoringOtherApps(true)
    
    0 讨论(0)
  • 2020-12-23 14:13

    Swift 2.0

    NSApp.activateIgnoringOtherApps(true)
    

    Helpful Programming Tips and Hacks

    0 讨论(0)
  • 2020-12-23 14:19

    Perhaps you want:

      [self.window setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces];
    

    Experiment with the other collection behaviors... I found NSWindowCollectionBehaviorMoveToActiveSpace was a bit buggy in 10.5 but it might be better now.

    0 讨论(0)
  • 2020-12-23 14:26

    But how to move the app to the user's current Space?

    You don't. Spaces hold windows, not applications. (That's why the collectionBehavior property is on NSWindow, not NSApplication.)

    0 讨论(0)
  • 2020-12-23 14:28

    To bring your app to the front:

    [NSApp activateIgnoringOtherApps:YES];
    

    Swift:

    NSApp.activateIgnoringOtherApps(true)
    

    Swift 3:

    NSApp.activate(ignoringOtherApps: true)
    
    0 讨论(0)
提交回复
热议问题