-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick Fix for Lower Value not set when Min Range is specified first... #1
base: master
Are you sure you want to change the base?
Conversation
…ue when minRange is set and upperValue hasn't been
Sorry its been so long. The upper value is never 0, its initialised to 1.0, equal to the controls initial max value. Setting the upper value to FLT_MAX doesn't really make sense. Im not 100% sure how to replicate you issue, if you can give me more detail I can have a look. Thanks |
Hi! I've got the same issue. Here is the way how to replicate it, change minimumValue and lowerValue in configureLabelSlider method from NMDemoTVC.m: - (void) configureLabelSlider
{
self.labelSlider.minimumValue = 20; // !!!!! Changed from 0 to 20
self.labelSlider.maximumValue = 100;
self.labelSlider.lowerValue = 50; // !!!!! Changed from 0 to 50
self.labelSlider.upperValue = 100;
self.labelSlider.minimumRange = 10;
} after that you see a bug in label slider:
The solution with setting FLT_MAX in default upperValue fixes the bug: - (void) configureView
{
// ...
// _upperValue = 1.0;
_upperValue = FLT_MAX;
// ...
} |
If you set the upperValue before setting the lowerValue then you don't have an issue. Probably by design, not really a bug...but...perhaps the slider default behaviour should be to move the upperValue along with the desired lowerValue if the upper < lower you are trying to set. A matter of opinion I think. However, if the slider allows crossover, then the lower should move past the upper and pin to the maximum if it exceeds. |
I haven't looked into this at all, but if you do this: slider.upperValue = [SettingsStore instance].maxAcceptableRange;
slider.lowerValue = [SettingsStore instance].minAcceptableRange; Everything is fine. If you do it in reverse: slider.lowerValue = [SettingsStore instance].minAcceptableRange;
slider.upperValue = [SettingsStore instance].maxAcceptableRange; Lower value gets drawn as 1 on the slider. Here's my code demonstrating the problem (just swap the two lines to see the issue): NMRangeSlider *slider = [[NMRangeSlider alloc] initWithFrame:CGRectMake(60, 110, 200, 30)];
slider.minimumRange = 30;
slider.minimumValue = 0;
slider.maximumValue = 240;
slider.stepValue = 1;
slider.continuous = YES;
[slider bk_addEventHandler:^(id sender) {
self.minLabel.text = [NSString stringWithFormat:@"%i", (int) slider.lowerValue];
self.maxLabel.text = [NSString stringWithFormat:@"%i", (int) slider.upperValue];
} forControlEvents:UIControlEventValueChanged];
slider.upperValue = [SettingsStore instance].maxAcceptableRange;
slider.lowerValue = [SettingsStore instance].minAcceptableRange;
[self.view addSubview:slider]; |
@1ex Is right here - setting _upperValue = FLT_MAX; solves the issue |
setting the lowerValue before upperValue cause problem.
using @1ex solution does help to solve the issue here. |
In the setters, lowerValue depends on upperValue when minRange is set. If upperValue is still 0 then this causes lowerValue to not be set.
This commit is a quick fix (hack) that just calls setLowerValue a second time in the setLowerValue:upperValue method. It still doesn't solve the problem of the client using the properties to initialise the lower and upper values.
A better fix might be to have lower/upperValue initialise to -/+FLT_MAX or have lower value only adjust for minRange if (upperValue != some-pre-decided-init)...it's probably worth a bit more thought...
Thx for the component. I've given it 5 stars on CocoaControls :)