我必须有两个与一个 View 关联的 subview 。一个是处理右键单击的透明 View ,另一个是带有 nsimageview subview 的 nsview。由于某种原因,右键单击可以作用于 super View 的任何部分,除了 nsimageview 内的部分。透明 View 位于另一个 View 之上,但鼠标右键按下事件未触发。
最佳答案
我最终通过子类化 ImageView 并覆盖 HitTest 方法以返回 nil 解决了这个问题。完整的实现如下:
@implementation TTBaseImageView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
[super drawRect:dirtyRect];
}
-(BOOL)isFlipped
{
return YES;
}
-(BOOL)acceptsFirstResponder
{
return NO;
}
-(BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
return NO;
}
-(NSView *)hitTest:(NSPoint)aPoint
{
return nil;
}
@end
关于macos - NSView subview 右键单击无法在 nsimageview 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18104039/