我想在otherMouseDown上检测rightMouseDown和NSTableView。我搜索了一下,并找到了一些答案,使用menuForEvent但是,当鼠标右键按下时,它就被调用了,但是我想检测鼠标点击nstableview。
发布于 2016-07-04 02:08:34
有几种方法:
如果子类为NSTableView,则可以重写NSResponder rightMouseDown:或otherMouseDown:函数。
如果不想子类NSTableView,则可以附加本地监视器。问题是,这个本地监视器将查看应用程序中指定的每个事件,因此您必须进行一些检查,以确保鼠标在发生右鼠标或其他鼠标下降事件时位于表视图中。
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskRightMouseDown|NSEventMaskOtherMouseDown handler:^NSEvent * _Nullable(NSEvent * _Nonnull theEvent) {
if ([theEvent window] == [tableView window]) {
NSPoint event_location = [theEvent locationInWindow];
NSPoint local_point = [[tableView superview] convertPoint:event_location fromView:nil];
if (NSPointInRect(local_point, [tableView frame])) {
}
}
return theEvent;
}];请注意,此方法返回一个id对象,需要在必要时传递到removeMonitor (与NSNotificationCenter addObserverForName:一样)。
https://stackoverflow.com/questions/38175679
复制相似问题