gpt4 book ai didi

objective-c - 单击按钮但不升起窗口

转载 作者:太空狗 更新时间:2023-10-30 03:50:23 26 4
gpt4 key购买 nike

iTunes 迷你播放器(仅举一个例子)支持点击,当使用播放/暂停和音量控制时,应用程序不会被带到最前面。

这是怎么做到的?

我一直在浏览 Apple 的文档,并在 Cocoa Event-Handling Guide, Event Dispatch 中继续进行一些工作。它指出:

Some events, many of which are defined by the Application Kit (type NSAppKitDefined), have to do with actions controlled by a window or the application object itself. Examples of these events are those related to activating, deactivating, hiding, and showing the application. NSApp filters out these events early in its dispatch routine and handles them itself.

因此,根据我有限的理解 ( How an Event Enters a Cocoa, Application ) 子类化 NSApplication 并覆盖- (void)sendEvent:(NSEvent *)theEvent 应该捕获每个鼠标和键盘事件,但仍然会在单击时引发窗口。因此,要么在 NSApplication 看到事件之前引发窗口,要么我遗漏了其他内容。

我看过 Matt Gallagher 的 Demystifying NSApplication by recreating it ,不幸的是,Matt 没有涵盖事件队列,所以除此之外,我很困惑。

如有任何帮助,我们将不胜感激。

编辑添加:Lloyd's Lounge 找到一个帖子他在其中谈到了同样的问题并链接到 CocoaBuilder, capture first right mouse down 的帖子.我目前正在尝试那里提供的代码,经过一些摆弄并重新激活 [theEvent type] 的 NSLog 后,鼠标左键事件被捕获。

现在,左键单击窗口使其向前产生一系列事件类型,13, 1, 13,它们又是 NSAppKitDefined、NSLeftMouseDown 和 NSAppKitDefined。我可以过滤掉它们或找到它们的去向吗?

最佳答案

这可以通过一个 NSPanel 来实现,它被设置为在停用时不隐藏并且仅在需要时成为关键。这也假设您将使用的控件返回 YES-acceptsFirstMouse:; NSButton默认这样做。

您可以通过 IB 为面板关闭停用隐藏标志,但您需要向面板发出 -setBecomesKeyOnlyIfNeeded:YES 消息以阻止它和应用程序继续运行按钮点击次数。

关于objective-c - 单击按钮但不升起窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1498593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com