Re: What is the best way to get an NSSlider to respond to the mouse scroll wheel?
Re: What is the best way to get an NSSlider to respond to the mouse scroll wheel?
- Subject: Re: What is the best way to get an NSSlider to respond to the mouse scroll wheel?
- From: "Michael Ash" <email@hidden>
- Date: Thu, 27 Nov 2008 19:04:04 -0500
On Thu, Nov 27, 2008 at 12:08 PM, Graham Cox <email@hidden> wrote:
>
> On 28 Nov 2008, at 3:18 am, Michael A. Crawford wrote:
>
>> I assume I can sub-class the control but I wondering if there is a better
>> way. I'm using a circular slider and would like it to rotate when I roll
>> the scroll wheel up or down.
>
> You can just implement the -scrollWheel: method in a category. For example:
>
> @implementation NSSlider (Scrollwheel)
>
>
> - (void) scrollWheel:(NSEvent*) event
> {
> [self setFloatValue:[self floatValue] + [event deltaY]];
> [self sendAction:[self action] to:[self target]];
> }
>
>
> @end
Please don't do this! It will apply to every single slider in your
process, even ones you didn't create yourself, and if at some point
Apple adds their own -scrollWheel: implementation, it will end up
fighting with yours and it's not guaranteed whose will win. It's much
better to simply subclass NSSlider and use your subclass anywhere you
want a scroll-wheelable slider. I'm not sure why the OP is averse to
subclassing, unless he's just asking if there's any built-in
functionality already there. It's going to be perhaps ten lines of
code and will get the job done.
Mike
_______________________________________________
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