Re: Can NSView and NSImageView respond to Mouse Clicks?


Dave
 

Hi,

This is for NSView, I’ve not looked into NSImageView as yet.

I tried adding a Gesture Recognizer which sort of work except the Handler gets calls more than nice when I mouse down.

Basically, I want to detect a Mouse Down on an NSView Subclass and when it occurs display a Pop-Up Menu. Don’t understand why I'm getting multiple calls - see code below.

All the Best
Dave

-(instancetype) initWithCoder:(NSCoder*) theDecoder
{
self = [super initWithCoder:theDecoder];
if (self == nil)
return nil;

NSLog(@"initWithCoder: %@",self.identifier);
[self setupView];

return self;
}


-(void) setupView
{
NSPressGestureRecognizer* myGestureRecognizer;

myGestureRecognizer = [[NSPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionPressGesture:)];
myGestureRecognizer.minimumPressDuration = 0.001;
myGestureRecognizer.buttonMask = 1;
myGestureRecognizer.delaysPrimaryMouseButtonEvents = NO;
[self addGestureRecognizer:myGestureRecognizer];
}

-(void) actionPressGesture:(LTWTestViewCell*) theSender
{
NSLog(@"actionPressGesture: %@",self.identifier);
}

On 20 Sep 2018, at 02:03, Alex Zavatone via Groups.Io <zav=mac.com@groups.io> wrote:

You can add a gesture to it IIRC.
On Sep 19, 2018, at 1:34 PM, Dave <dave@looktowindward.com> wrote:

Hi,

Can an Custom NSView respond to Mouse Clicks via IBActions?

Can the same be done with NSImageView? I’ve added an image view and connected it to an IBAction method define in my View Controller, but when I click the NSImageView nothing happens…..

Any help greatly appreciated.

All the Best
Dave


Join cocoa@apple-dev.groups.io to automatically receive all group messages.