在 Cocoa 中启动后停用代理应用程序
在调用 applicationDidFinishLaunching:
委托方法后,应该调用什么方法来停用应用程序?或者也许有更好的地方可以做到这一点? NSApplication
的 deactivate
方法的文档说我不应该直接调用这个方法,因为 AppKit 更知道如何停用东西。
What method should be called to deactivate an app right after it's launch in applicationDidFinishLaunching:
delegate method has been called? Or maybe there is a better place to do that? The documentation for deactivate
method for NSApplication
says that I shouldn't call this method directly since AppKit knows better how to deactivate stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许使用
-[NSApplication hide:]
会起作用,或者可能使用-[NSRunningApplication activateWithOptions:]
激活另一个应用程序(仅限 10.6)。但是,我预计使用deactivate:
不会出现很多问题。Maybe using
-[NSApplication hide:]
would work, or perhaps activate another app using-[NSRunningApplication activateWithOptions:]
(10.6 only, tho). However, I don't foresee many problems with usingdeactivate:
.目前尚不清楚您想要实现什么目标。
您可以使用
-hide:
停用您的应用程序。如果它确实满足您的需要,我也会毫不犹豫地使用-deactivate
。只是正常应用程序不会显式地自行停用;我认为文档就是这么说的。但是,如果您在 Info.plist 中设置
LSUIElement
,您的应用程序在启动时不应变为活动状态;它也不会有菜单栏或停靠栏图标。It's not clear what you're trying to achieve.
You can use
-hide:
to deactivate your app. I also wouldn't hesitate using-deactivate
if it actually does what you need. It's just that normal applications do not explicitly deactivate themselves; I think that's what the documentation is saying.However, if you set
LSUIElement
in Info.plist your application should not become active when launched; it also won't have a menu bar or dock icon.