NMRangeSlider icon indicating copy to clipboard operation
NMRangeSlider copied to clipboard

Frame of handles are not set on parent view viewWillAppear:

Open ghost opened this issue 10 years ago • 11 comments

Try this in demo without any changes in other places:

- (void) configureLabelSlider
{
    self.labelSlider.minimumValue = 10;
    self.labelSlider.maximumValue = 100;

    self.labelSlider.lowerValue = 10;
    self.labelSlider.upperValue = 100;

    self.labelSlider.minimumRange = 10;
}

You will see that lowerLabel stiil 0, etc... and you cannot update it till viewDidLoad, cause frames are set only in layout step.

ghost avatar Aug 11 '14 08:08 ghost

Hi,

The reason the lowerValue is not correct is actually todo with some range checking when setting the value. Try setting the upprtValue first then the lowerValue. Everything should work.

Although I am not totally sure how this is related to the subject of frame handles not set on superview?

muZZkat avatar Aug 11 '14 08:08 muZZkat

lowerValue is correct, but if you will try to update frame of self.lowerLabel before parent view viewDidAppear, you will get that lowerCenter is {0;0}. I just want set up frames before my view appears on screen, but it impossible, cause you set frames of handles only in layoutSubview:

ghost avatar Aug 11 '14 10:08 ghost

OK, I understand now.

Not really sure what would be the correct way to this. Maybe the subviews can be setup in configureView, this seems to fix that particular bug.

muZZkat avatar Aug 11 '14 10:08 muZZkat

Otherwise, maybe lowerCenter/upperCenter should not be calculated from the handles subview, the current code actually uses _lowerHandle.center, this would be incorrect if the image used alignment insets....

muZZkat avatar Aug 11 '14 10:08 muZZkat

May be you need make slider class more generic and add labels in it? I had no time to look more close on it, but if you want, later I can make PR.

ghost avatar Aug 11 '14 10:08 ghost

Yeah not really interested in adding labels to the control, its a very specific use case and could be require in a million different ways.

For now, just call [self.labelSlider layoutSubviews] at the start of the configureLabelSlider and it should work around your issue.

muZZkat avatar Aug 11 '14 10:08 muZZkat

I have the same issue.

@muZZkat you cannot call layoutSubviews directly, instead you should call setNeedsLayout, you can pump up layout update using layoutIfNeeded.

pronebird avatar Aug 21 '14 11:08 pronebird

@pronebird, I reworked the code a little so some of the initial frames get calculated in the init method. Haven't had time to push the final fix, I will try and get onto it tonight.

muZZkat avatar Aug 21 '14 11:08 muZZkat

@muZZkat thanks a lot. I think I will calculate centers manually for the time being, as it does not seem to be a big deal, although I admit, it can get handy. Thanks for such an awesome control!

pronebird avatar Aug 21 '14 11:08 pronebird

Hi @muZZkat, any headway on this issue? I am trying to load labels based on the location of the handles, and the handle center CGPoints are inaccurate until they are adjusted.

bliebman avatar Aug 29 '14 17:08 bliebman

any news on this issue ?

robinmonjo avatar Dec 15 '14 14:12 robinmonjo