因此,我有一个菜单栏应用程序,其中有一个自定义视图中的滑块:我希望能够在拖动时按下选项键,以使滑块加速到增量。
现在,一切正常.除了我找不到一种方式通知我的菜单应用程序,选项键正在按下。以下是我尝试过的:
NSEvent.addGlobalMonitorForEvents- "Note that your handler will not be called for events that are sent to your own application."
NSEvent.addLocalMonitorForEvents- "Your handler will not be called for events that are consumed by nested event-tracking loops such as control tracking, _menu tracking_, or window dragging"
NSApplication.shared.currentEvent- This dosesn't work because the flagsChanged event isn't handled by the app, so this value is set to another value (mouse button presses).
flagsChanged(with event: NSEvent)- This doesn't get called. I've set the `viewController` to `acceptFirstResponder` as well as resigned the first responder of the view. Also, I've subclassed the view and overridden `flagsChanged` and that hasn't worked.
因此,我试图找出当按下选项键时,如何通知我。这个是可能的吗?如果你有什么问题我可以澄清。
发布于 2019-05-02 14:27:57
在自定义滑块视图的mouseDragged方法中,只需检查NSEvent参数的modifierFlags,看看它是否包含选项键。
--
因为可以解释滑块是一个实际的NSSlider,如果是这样的话,那么滑块的控件实际上是用一个NSSliderCell实现的,鼠标跟踪将从mouseDown的视图传递到mouseDown中的单元格,所以NSSlider的mouseDragged不会被调用,而是必须在单元格的trackMouse:inRect:...方法中工作。但是,如果您使用的是NSSlider,那么您可能只想使用altIncrementValue。
https://stackoverflow.com/questions/55952719
复制相似问题