Date
1 - 8 of 8
Can NSView and NSImageView respond to Mouse Clicks?
Dave
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 |
|
Keary Suska
NSView doesn’t have action handling—you get that from NSControl. If you need action handling, you might need an NSControl subclass rather than an NSView subclass. That being said, you can call your action method “manually” in an event handler for NSView.
toggle quoted message
Show quoted text
As for NSImageView, It doesn’t look like you can specify action handling in Xcode. Have you tried calling -sendActionOn: on your image view? Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" On Sep 19, 2018, at 12:34 PM, Dave <dave@...> wrote: |
|
Andy Lee
On Sep 19, 2018, at 2:34 PM, Dave <dave@...> wrote:
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…..From the docs: <https://developer.apple.com/documentation/appkit/nsimageview?language=objc> Note--Andy |
|
Alex Zavatone
You can add a gesture to it IIRC.
toggle quoted message
Show quoted text
On Sep 19, 2018, at 1:34 PM, Dave <dave@...> wrote: |
|
Dave
Hi,
toggle quoted message
Show quoted text
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@...> wrote: |
|
Sean McBride
On Thu, 20 Sep 2018 11:36:10 +0200, Dave said:
Basically, I want to detect a Mouse Down on an NSView Subclass and whenSuggestion: open NSView.h and search for "menu", there are API like menuForEvent: and willOpenMenu: that look useful for your case. Cheers, Sean |
|
Jack Brindle
NSView inherits from NSResponder. That gives NSView access to mouseDown, mouseUp and a whole host of other important calls.
toggle quoted message
Show quoted text
What this really means is that you can implement - (void)mouseDown:(NSEvent *)event; or v- (void) mouseUp:(NSEvent *)event; in your NSView subclass and handle mouse events the way you like, which includes generating IBAction calls to other objects that need to be notified of mouse events in your view. The event object will contains information about where the cursor was when the mouse down or up even occurred, which you can use to determine exactly where in the view the hit occurred, and even when. Note that any control embedded in the view will take precedence over the view itself, so that it gets a chance to handle the mouse down first. After all these years, I still find it really cool the way events and the responder chain works, and gives us so much power to create great user interfaces. Jack On Sep 20, 2018, at 4:36 AM, Dave <dave@...> wrote: |
|
Dave
Thanks a lot, I actually found this yesterday and now have it working using the mouseDown method to display a Popup - work a treat!
toggle quoted message
Show quoted text
All the Best Dave
|
|