我在单击按钮时显示弹出菜单。问题是,当该菜单打开时,计时器不再工作:
显示菜单:
[_menu popUpMenuPositioningItem:nil atLocation:point inView:nil];
单击按钮后,我的计时器(在弹出窗口之前调用)不再发送消息。
[NSTimer scheduledTimerWithTimeInterval:0.50
target:self
selector:@selector(myMethod:)
userInfo:nil
repeats:YES];
还尝试过 [NSEvent addGlobalMonitorForEventsMatchingMask..] 甚至 CGEventTapCreate。什么都没有被调用。
如何使弹出窗口不阻塞/模式化?我知道这是可能的,我见过另一个应用程序做到了。感谢您的任何想法。
最佳答案
问题可能是 NSTimer 没有在正确的模式下运行。尝试通过创建 NSRunLoop 对象来获取当前运行循环。然后使用方法 addTimer:forMode: 将计时器添加到 NSModalPanelRunLoopMode(在您刚刚创建的运行循环对象中)。您可以在 Apple 文档中阅读更多相关信息:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSRunLoop_Class/Reference/Reference.html
关于objective-c - NSMenu 阻塞计时器/全局事件监视器/等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15233576/