Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mouseEntered and mouseExited not called in NSImageView SubClass

I created a subclass of NSImageView to capture mouseEntered and mouseExited events. But only mouseUp and mouseDown events are getting called. How to capture the mouseEntered and mouseExited events in NSImageView subclass?

like image 877
Ram Avatar asked Jun 25 '12 10:06

Ram


1 Answers

If You want to use mouseEntered: and mouseExited: You need to use NSTrackingArea. Here is reference NSTrackingArea Class Reference.

Example:

//Add this to Your imageView subclass  -(void)mouseEntered:(NSEvent *)theEvent {     NSLog(@"Mouse entered"); }  -(void)mouseExited:(NSEvent *)theEvent {     NSLog(@"Mouse exited"); }  -(void)updateTrackingAreas {      [super updateTrackingAreas];     if(trackingArea != nil) {         [self removeTrackingArea:trackingArea];         [trackingArea release];     }      int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);     trackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds]                                                  options:opts                                                    owner:self                                                 userInfo:nil];     [self addTrackingArea:trackingArea]; } 
like image 88
Justin Boo Avatar answered Sep 19 '22 23:09

Justin Boo