如何将 NSWindow 置于当前空间的前面?
我正在使用此代码来调出我的窗口:
[self.window makeKeyAndOrderFront:self];
[self.window setOrderedIndex:0];
但它通常会位于其他窗口下方或显示在我上次打开它的其他 Space 桌面中。如何使其始终显示在用户的“前面”?
更新 我从之前提出的问题中找到了答案;使窗口显示在其他窗口的顶部: [NSApp activateIgnoringOtherApps:是];
但是如何将应用移动到用户当前的空间呢?
I'm using this code to bring up my window:
[self.window makeKeyAndOrderFront:self];
[self.window setOrderedIndex:0];
But often it will be beneath other windows or displayed in other Space desktop that I last open it in. How do I make it always appear "in front" to the user?
Update
I found the answer from previously asked question; make the window show up to the top of other windows:
[NSApp activateIgnoringOtherApps:YES];
But how to move the app to the user's current Space?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
要将您的应用程序置于最前面:
Swift:
Swift 3:
To bring your app to the front:
Swift:
Swift 3:
也许您想要:
尝试其他集合行为...我发现
NSWindowCollectionBehaviorMoveToActiveSpace
在 10.5 中有点错误,但现在可能会更好。Perhaps you want:
Experiment with the other collection behaviors... I found
NSWindowCollectionBehaviorMoveToActiveSpace
was a bit buggy in 10.5 but it might be better now.斯威夫特 5.0 +
Swift 5.0 +
语法似乎与 Swift 2 有点不同:
The syntax seems to be a little different with Swift 2:
斯威夫特3.0
Swift 3.0
如果您希望您的应用程序位于最前面,即使其最小化并且已将其激活(给定活动焦点),那么请使用这两个:
如果您只想将其带到前面,不给它焦点,只需使用:
If you want to your app to come to the front, even if its minimised and have it activated (given active focus), then use both of these:
If you only want to bring it to the front, without giving it focus, just use:
你不知道。空间包含窗口,而不是应用程序。 (这就是为什么
collectionBehavior
属性位于NSWindow上,而不是NSApplication上。)You don't. Spaces hold windows, not applications. (That's why the
collectionBehavior
property is on NSWindow, not NSApplication.)Swift 2.0
有用的编程技巧和技巧
Swift 2.0
Helpful Programming Tips and Hacks