> On Dec 29, 2015, at 3:31 PM, Roland King <r...@rols.org> wrote:
> 
>> 
>> 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
> 
> No they don’t - changing that to to NSLeftMouseUpMask has a similar effect to 
> turning off ‘continuous’, all clients get one event, at the end, so the live 
> updating realtime display doesn’t work. 
> 

Hey Roland, good call. I haven’t tried out Cocoa Bindings and figured 
(incorrectly) that the Bindings functionality is different than NSControl 
action/target and the two would run in parallel without interfering with each 
other. I see now that this isn’t the case.

After some poking around and experimentation, I came up with the following:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.lastSliderValue = -1;
    self.slider.action = @selector(valueChanged:);
    self.slider.target = self;
    [self.slider sendActionOn:NSLeftMouseUpMask];
     self.slider.continuous = YES;
}

- (IBAction)valueChanged:(id)sender
{
    NSLog(@"\n*** [\n\tNew Slider Value %0.4f\n\tLast Slider Value = %0.4f\n]", 
[sender floatValue], self.lastSliderValue);

    if( [sender floatValue] == self.lastSliderValue )
    {
        NSLog(@"\nUser finished moving slider.\nFinal slider value: %0.4f", 
[sender floatValue]);
        self.lastSliderValue = -1;
    }
    else
        self.lastSliderValue = [sender floatValue];
}

What I first found out is that setting the ‘continuous’ property to NO, I would 
only ever get a value changed message upon the mouse up. Even if I set up a 
binding between this object’s value changed and my view controller. 

However, if I set the ‘continuous’ property to YES, then it’s hard to find out 
which value change is due to the Mouse Up event. This is because there isn’t 
any way to find out the event that triggered the value changed (e.g. Mouse Up).

What I rely upon for this solution is that when the Slider is configured to 
send it's action message upon Mouse Up and sending continuous events, I get a 
value changed for every mouse move while the mouse is pressed. Then one more 
value changed when mouse up happens. However, when the mouse up happens, the 
value hasn’t changed, I’m just now getting the action message due to the 
‘sendActionOn’ parameter. So if the value hasn’t changed since the last 
message, I infer that there was a mouse up.

Seems to be working but would be interested to hear what you think.

Doug Hill
_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to