Unrecognised selector sent to instance when adding tracking area

51 Views Asked by At

I have an NSImage in an NSPanel in which I'd like to get the mouse X, Y co-ords.

If I set the NSImage layer content withlayer.content =splitNSImage (where splitNSImage is an NSImage created from a URL)and then

NSRect layerBounds = [layer bounds];
NSTrackingAreaOptions options = (NSTrackingActiveAlways|NStrackingInVisibleRect|NSTrackingMouseEnter|
NSTrackingMouseExit|NSTrackingMouseMoved);
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:layerBounds owner:self userinfo:nil];
[[layer contents] addTrackingArea:trackingArea];

I get a runtime error "Thread 1: "-[NSImage addTrackingArea:]: Unrecognised selector sent to instance 0x600003335400" on the last line.

If I use the use [NSPanel contentView] instead of [layer contents] it works OK but gives the mouse co-ords (in the MouseMoved event) in the panel rather than the imageView

0

There are 0 best solutions below