If you really only want to be informed of the final value, you can just set
'Continuous' to NO in IB.

Mike's technique is good though, and can provide better UI if you have a
cheap action you can take continuously and something more expensive that
cannot afford to do live.  For this, use a delay of greater than 0.0, use
-performSelector:withObject:afterDelay:i*nModes*:, and pass probably
NSRunLoopCommonModes
for modes.

This also handles full keyboard access.  If you tried to override
stopTracking, you'd probably break the case of the user tabbing to your
slider and hitting the right arrow key.
Thanks Mike!

-Ken
Cocoa Frameworks

On Fri, Oct 17, 2008 at 2:01 PM, James Walker <[EMAIL PROTECTED]>wrote:

> Michael Ash wrote:
>
>> On Fri, Oct 17, 2008 at 2:33 PM, James Walker <[EMAIL PROTECTED]>
>> wrote:
>>
>>> I'd like to be notified when the mouse button has been released after
>>> some
>>> live tracking of a slider.  I can probably do it by subclassing NSSlider
>>> and
>>> NSSliderCell, for instance overriding [NSCell
>>> stopTracking:at:inView:mouseIsUp:], but is there an easier way?
>>>
>>
>> There is indeed. Write your action like this:
>>
>> - (IBAction)sliderMoved:(id)sender {
>>    SEL trackingEndedSelector = @selector(sliderEnded:);
>>    [NSObject cancelPreviousPerformRequestsWithTarget:self
>> selector:trackingEndedSelector object:sender];
>>    [self performSelector:trackingEndedSelector withObject:sender
>> afterDelay:0.0];
>>
>>    // do whatever you want to do during tracking here
>> }
>>
>> - (void)sliderEnded:(id)sender {
>>    // do whatever you want to do when tracking ends here
>> }
>>
>> It may not be immediately obvious why this works. Delayed performs
>> happen in the default runloop mode (unless you specify otherwise using
>> the variant that has modes: at the end). Event tracking happens in a
>> special event tracking runloop mode. So the delayed perform won't
>> happen until the user lets go of the mouse button.
>>
>> To keep these delayed performs from piling up, this method first
>> cancels any previous ones before scheduling the new one. An alternate
>> method would be to have some sort of flag that guarantees you only
>> schedule one, but this way is simpler and doesn't require a flag.
>>
>> This technique works for any control that uses the event tracking
>> mode, such as continuous buttons, menus, and other such things, but
>> it's most commonly used for sliders.
>>
>
> Wow, I never would have come up with that on my own.  Thanks a lot!
> --
>  James W. Walker, Innoventive Software LLC
>  <http://www.frameforge3d.com/>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com
>
> This email sent to [EMAIL PROTECTED]
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to