Re: Pressable Button
Re: Pressable Button
- Subject: Re: Pressable Button
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 16 Dec 2008 18:56:54 +0100
On Dec 16, 2008, at 4:02 PM, Gerriet M. Denkmann wrote:
I am trying to build a pressable button: an on-off button (subclass
of NSButton), which, if pressed for more than 0.3 seconds, displays
a context menu.
My idea was:
Start a non-repeating timer in mouseDown: and schedule it with
NSEventTrackingRunLoopMode.
In mouseUp: invalidate the timer.
And in timerFired: display the context menu.
But: mouseUp: is never called. So: where should I invalidate the
timer?
And: if I send: [ NSMenu popUpContextMenu: menu withEvent:
mouseDownEvent forView: self ]
the button gets all messed up: no more drawRect: on mouse up, no
action sent.
Obviously I am doing it all wrong.
I have a button like this.
I use performSelector:withObject:afterDelay: in the mouseDown:, cancel
the delayed perform in mouseDragged: if the mouse cursor is outside
the button frame, put back the delayed perform if the mouse cursor
comes back in the button frame.
On mouseUp: I cancel the delayed perform if needed.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden