Re: Getting the final value from an NSSlider drag
Re: Getting the final value from an NSSlider drag
- Subject: Re: Getting the final value from an NSSlider drag
- From: Doug Hill <email@hidden>
- Date: Tue, 29 Dec 2015 15:23:10 -0800
> On Dec 29, 2015, at 2:45 PM, Ken Thomases <email@hidden> wrote:
>
> On Dec 29, 2015, at 5:44 AM, Graham Cox <email@hidden <mailto:email@hidden>> wrote:
>>
>> On 29 Dec 2015, at 7:44 PM, Roland King <email@hidden> wrote:
>>>
>>> I can subclass NSSlider or possibly NSSliderCell but that sounds like a whole world of pain, if I have to do that I’ll probably just put a coalescing delay into the whole thing which waits 1/2 second after an update before it actually does the update.
>>>
>>> Any good ways to do this?
>>
>> In your action method, call another method that handles the final value using -performSelector:withObject:afterDelay: but just before you do that, call +[NSObject cancelPreviousPerformRequestsWithTarget:...] for the same message. This schedules a deferred message but immediately cancels it as long as the values come pouring in. On the last time, when you stop moving the slider, the final -performSelector will get to its target and do its work. The afterDelay parameter can be set to whatever value you think you’ll need to allow for a slowly moved slider NOT to fire the final message. I typically use 0.1sec.
>
> This gives false positives if the user simply stops moving the mouse but doesn't release the mouse button. There's no delay you can specify that avoids this, since there's no upper bound to how long the user can hold the mouse button. (With assistive technologies, the user doesn't even have to be actually holding anything for the duration.)
>
> Regards,
> Ken
If you want to know when the last value is sent during mouse tracking, set the ‘actionOn’ property to mouse-up.
So, something like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.slider.action = @selector(valueChangedFinally:);
self.slider.target = self;
[self.slider sendActionOn:NSLeftMouseUpMask];
}
- (IBAction)valueChangedFinally:(id)sender
{
NSLog(@“Here is the final slider value upon mouse up:%@", [sender stringValue]);
}
Presumably the other bindings/etc. code would still work to update your real-time display.
Doug Hill
_______________________________________________
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