Question

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.

Était-ce utile?

La solution

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top