- (IBAction)sliderValueChanged:(id)sender
{
double range = [sender maxValue] - [sender minValue];
double tickInterval = range / ([sender numberOfTickMarks] - 1);
double relativeValue = [sender doubleValue] - [sender minValue];
// Get the distance to the nearest tick.
int nearestTick = round(relativeValue / tickInterval);
double distance = relativeValue - nearestTick * tickInterval;
// Change the check here depending on how much resistance you
// want, or if you don't want it to depend on the tick interval.
if (fabs(distance) < tickInterval / 8) {
[sender setDoubleValue:[sender doubleValue] - distance];
}
}
Then you have to make the slider continously perform the action when moved, instead of just when releasing it. This can be done either by checking the "Continous" check button in Interface Builder or programmatically using:
- (void)setContinuous:(BOOL)flag
on the slider instance.
There might be a better to do this, if anyone knows about it I'm all ears :)
0 comments:
Post a Comment