Question

I need to create a quick demo app (asap). It has a NSImageView (with a full window sized photo) and the mouse point clicks, drags and moves over this.

There is also an NSTextField (Label) to show the mouse event and position over the window.

I've created a project using the Cocoa app template, and create a new ViewController, added that view controllers view to the windows contextView, and the NSImageView shows up fine - as does the label.

However events such as

- ( void ) mouseDown:( NSEvent * )event;
- ( void ) mouseMoved:( NSEvent * )event;

Don't do anything. If I have an NSLog in there, they never get hit.

I have set:

- ( BOOL ) becomesFirstResponder
{
    return YES;
}

but that also doesn't make any difference.

Can someone please point out what I'm doing wrong? I'm an iOS Dev of 2+ years and this is my first Mac OS X app. I have to get this working in the next 24hours :(

Was it helpful?

Solution 2

The mouse events were trying to be used in the 'View Controller' class.

I've since found a sample code (3rd party) that shows they have to be in the 'NSView' object, so I've had to create a custom NSView object programatically to track the mouse and it's all working.

Here's the URL:

http://www.markdouma.com/developer/MouseMovedvsTrackingAreas.zip

OTHER TIPS

To catch mouse down/up events, you should subclass NSImageView and define mouseDown:/mouseUp: there. Then you can forward these events to controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top