作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有以下代码用于监听 View 外的鼠标事件(NSView 的子类)。这很好用,但我不知道如何将 NSEventMasks 通过管道连接在一起。我基本上想在 NSEventMask.LeftMouseDownMask
、NSEventMask.RightMouseDownMask
和 NSEventMask.OtherMouseDownMask
上触发相同的事件监听器。
有谁知道如何将它们组合在一起,或者在 Swift 中是否可行?
工作代码
localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMask.LeftMouseDownMask) { (event: NSEvent) -> NSEvent? in
// Event handling...
return event
}
最佳答案
This answer可能对你有帮助。
简而言之,您现在可以使用数组,所以这似乎让编译器很高兴:
localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask([.LeftMouseDownMask, .RightMouseDownMask, .OtherMouseDownMask]) { (event: NSEvent) -> NSEvent? in
// Event handling...
return event
}
关于swift - 在 'addLocalMonitorForEventsMatchingMask' 中将 NSEventMask 管道连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34394550/
这里又出现了另一个内存泄漏问题。我有一个 NSStatusItem,我正在 try catch 鼠标点击并使用react。以下代码会导致 Instruments 报告泄漏,删除此代码会导致 Instr
我有以下代码用于监听 View 外的鼠标事件(NSView 的子类)。这很好用,但我不知道如何将 NSEventMasks 通过管道连接在一起。我基本上想在 NSEventMask.LeftMouse
以下代码不会抑制我的应用程序中的鼠标拖动: [NSEvent addLocalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask handler:^
我是一名优秀的程序员,十分优秀!