문제

I have to two subviews associated with a view. One is a transparent view that handles a right click, the other a nsview with an nsimageview subview. For some reason the right click works over any part of the superview except the part within the nsimageview. The transparent view is on top of the other view yet the right mouse down event is not firing.

도움이 되었습니까?

해결책

I finally solved it by subclassing the image view and overriding the hit test method to return nil. The full implementation is below :

@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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top