gpt4 book ai didi

cocoa - 当弹出窗口位于状态栏中时,NSPopover transient

转载 作者:行者123 更新时间:2023-12-03 16:02:10 27 4
gpt4 key购买 nike

我正在制作一个位于状态栏中的应用程序。当点击状态项时,会弹出 NSPopover。

看起来像这样:

enter image description here

问题是:我希望它是“暂时的”,也就是说,如果我单击弹出窗口之外的任何位置,它就会关闭。虽然当弹出窗口位于窗口中时 NSPopoverBehaviorTransient 工作正常,但当它位于状态栏中时它不起作用。

我如何自己实现这种行为?

最佳答案

结果很简单:

- (IBAction)openPopover:(id)sender
{
// (open popover)

if(popoverTransiencyMonitor == nil)
{
popoverTransiencyMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask handler:^(NSEvent* event)
{
[self closePopover:sender];
}];
}
}

- (IBAction)closePopover:(id)sender
{
if(popoverTransiencyMonitor)
{
[NSEvent removeMonitor:popoverTransiencyMonitor];

popoverTransiencyMonitor = nil;
}

// (close popover)
}

但并不容易的是,从 NSStatusItem 中弹出弹出窗口会出现一些令人讨厌的问题(当调用任务控制或空间切换到全屏窗口时,它的行为不符合预期)。我必须实现一个始终 float 在 NSStatusItem 上方的自定义窗口,并处理切换到全屏窗口等。这看起来很简单,但显然状态项不是为类似的事情而设计的;)

关于cocoa - 当弹出窗口位于状态栏中时,NSPopover transient ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9054244/

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