Skip to content
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

Slider not changing between colors when changing value #20

Closed
ghost opened this issue May 20, 2014 · 16 comments
Closed

Slider not changing between colors when changing value #20

ghost opened this issue May 20, 2014 · 16 comments

Comments

@ghost
Copy link

ghost commented May 20, 2014

self.recordPercentageSlider = [ASValueTrackingSlider new];
self.recordPercentageSlider.delegate = self;
self.recordPercentageSlider.frame = CGRectMake(20.0, 45.0, CGRectGetWidth(self.frame) - 2.0 * 20.0, 31.0);
//self.recordPercentageSlider.value = 1.0;
self.recordPercentageSlider.font = [UIFont fontWithName:@"AvenirNext-Medium" size:15.0];
self.recordPercentageSlider.tintColor = [UIColor autumnColorWithAlpha:ZTAlphaLevelFull];
[self.recordPercentageSlider addTarget:self action:@selector(recordPercentageValueChanged) forControlEvents:UIControlEventValueChanged];
[self.contentView addSubview:self.recordPercentageSlider];

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];
[self.recordPercentageSlider setNumberFormatter:numberFormatter];
self.recordPercentageSlider.popUpViewAnimatedColors = @[[UIColor carbonColorWithAlpha:ZTAlphaLevelFull], [UIColor autumnColorWithAlpha:ZTAlphaLevelFull]];

This is the code I used for inserting the slider but will only display the first color in the array. I used these same lines for two different part of a project, both in table's cells, in which the animation did trigger while the other didn't.

@alskipp
Copy link
Owner

alskipp commented May 20, 2014

Here is the code I've just tried in a UITableViewCell subclass:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.recordPercentageSlider = [ASValueTrackingSlider new];
        self.recordPercentageSlider.delegate = self;
        self.recordPercentageSlider.frame = CGRectMake(20.0, 45.0, CGRectGetWidth(self.frame) - 2.0 * 20.0, 31.0);
        self.recordPercentageSlider.font = [UIFont fontWithName:@"AvenirNext-Medium" size:15.0];
        self.recordPercentageSlider.tintColor = [UIColor redColor];
        self.recordPercentageSlider.autoAdjustTrackColor = NO;
        [self.recordPercentageSlider addTarget:self action:@selector(recordPercentageValueChanged) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:self.recordPercentageSlider];

        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setNumberStyle:NSNumberFormatterPercentStyle];
        [self.recordPercentageSlider setNumberFormatter:numberFormatter];
        self.recordPercentageSlider.popUpViewAnimatedColors = @[[UIColor orangeColor], [UIColor purpleColor]];
    }
    return self;
}

The colors animated as expected. I also tried setting up the slider in a table cell in the storyboard and setting the animated colors in awakeFromNib and it behaved as expected.

Could you offer anymore info to help me track down the problem. Could you also check the colors you set to make sure they are what you expected in the following line:

self.recordPercentageSlider.popUpViewAnimatedColors = @[[UIColor carbonColorWithAlpha:ZTAlphaLevelFull], [UIColor autumnColorWithAlpha:ZTAlphaLevelFull]];

@ghost
Copy link
Author

ghost commented May 27, 2014

Just copies the code snippet you posted, and it worked in one situation and not in the other.
The only major difference between the two situations that I could think could cause a problem is:
The one that didn't work was a cell part of a uitableviewcontroller from the storyboard and was initialized with initWithCoder
The other one was created in programmatically with initWithStyle:reuseIdentifier:

Nothing elaborate about the colors, only these:
The ZTAlphaLevelFull is 1.0
Carbon: return [UIColor colorWithRed:38/255.0 green:38/255.0 blue:38/255.0 alpha:alpha];
Autumn: return [UIColor colorWithRed:255/255.0 green:138/255.0 blue:9/255.0 alpha:alpha];

Any other info you need, just tell me and thanks again for your time

@alskipp
Copy link
Owner

alskipp commented May 28, 2014

Hi @aj1310,
I've still not managed to reproduce this bug. I thought it might have something to do with using it in a tableview with a large number of cells. In that case the cells are reused when scrolling - I thought perhaps that might cause the problem, but I've just tried that and it worked correctly.

Does the animation work initially then fail to update after some action, or does it never work in this instance?
Are you able to post a sample project online that exhibits the bug?

@DisobedientMedia
Copy link

Hi, I'm not sure if this is 100% related, but I've just come here to log an issue about animation colour not working correctly - depending on the min, max values and the stop positions.

here's my code

    slider.minimumValue = 1.0;
    slider.maximumValue = 5.0;    
    [slider setPopUpViewAnimatedColors:@[
                                        [UIColor redColor],
                                        [UIColor yellowColor],
                                        [UIColor greenColor]
                                        ]
                         withPositions:@[
                                         @1.0,
                                         @2.5,
                                         @5.0]
     ];

This results in incorrect values being calculated in ASValueTrackingSlider keyTimesFromSliderPositions:, in this case instead of returning 3 values evenly spaced from 0.0 to 1.0 I get

[
0.5,
0.875,
1.5
]

This results in the green colour never being shown when the slider is at 5 - it's still yellow.

If I do the same but adjust the maximumValue to 10.0 the colors work more as expected, (but still not quite if you look at the keyTimes output).

    slider.minimumValue = 1.0;
    slider.maximumValue = 10.0;

    // red, yellow, green
   [slider setPopUpViewAnimatedColors:@[
                                        [UIColor redColor],
                                        [UIColor yellowColor],
                                        [UIColor greenColor]
                                        ]
                         withPositions:@[
                                         @1.0,
                                         @5.0,
                                         @10.0]
     ];

results in keyTimes of

[
0.2222222,
0.6666667,
1.222222
]

Happy to open new Issue, but thought it might be of use here.
Thanks

@alskipp
Copy link
Owner

alskipp commented Jul 29, 2014

Hi @DisobedientMedia,
Thanks for the report. This is definitely a bug. Having a minimumValue above zero seems to cause the issue. By the way, if you just need the colors distributed evenly you don't need to set positions manually (obviously due to the bug, this isn't quite the case at the minute - whoops). I'll try and publish a fix ASAP.

Cheers,
Al

@DisobedientMedia
Copy link

Great, thanks. I tried the slider.popUpViewAnimatedColors = @[color1,color2,color3], but as you say, it didn't work as expected.

@alskipp
Copy link
Owner

alskipp commented Jul 30, 2014

Hi @DisobedientMedia,
I've just published a bug fix branch, here: https://github.com/alskipp/ASValueTrackingSlider/tree/anim_fix
This should fix the issue you were experiencing. Could you try this branch and confirm if it works for you? I'll then merge it into master.

Cheers,
Al

@DisobedientMedia
Copy link

Thanks Al, works as expected now. Much appreciated.
cheers,
Robin

@alskipp
Copy link
Owner

alskipp commented Jul 30, 2014

Hi @aj1310,
The issue you raised was back in May, so this could well be too late for you. However, if the slider that didn't animate correctly for you had a minimumValue greater than zero, it is very likely that this is the same bug. If you are still using the component then please try this fix to see if it solves the issue.

All the best,
Al

@alskipp
Copy link
Owner

alskipp commented Jul 30, 2014

Hi Robin,
Thanks for confirming the fix and thanks for raising the issue. Your sample code really helped track down the problem, so it's much appreciated.

Please pass on my greetings to the glorious north,
Al

@Jack-s
Copy link

Jack-s commented Aug 12, 2014

Hi @alskipp
I think I'm encountering a related issue (if you prefer I can open a separate issue).

I'm using ASValueTrackingSlider in a UITableViewCell with a a few values being passed for the animation, when the initial value of the slider is 0 it works correctly however if I set a different initial value the popupview and slider still start from the first color passed in and as a result don't reach the last color in the animation.

For example I'm setting 5 colors like the following

[self.accuracySlider setPopUpViewAnimatedColors:@[
                                                      [UIColor redColor],
                                                      [UIColor orangeColor],
                                                      [UIColor purpleColor],
                                                      [UIColor blueColor],
                                                      [UIColor greenColor]]];

And I'm then setting the value of the slider (in tableView:cellForRowAtIndexPath)

self.accuracySlider.value = 10.0;

In this case the popupview and slider never reach the green color.

If however I defer setting the sliders value it works correctly

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), 
dispatch_get_main_queue(), ^{
           self.accuracySlider.value = 10.0;
        });

@alskipp
Copy link
Owner

alskipp commented Aug 13, 2014

Hi @Jack-s
Thanks for reporting this. Could I ask a few questions: Is this issue occurring while using the latest release? Could you try your project with this branch https://github.com/alskipp/ASValueTrackingSlider/tree/popup_refactor, there have been significant internal changes, which may help.

I've been unable to reproduce the issue, which makes it very difficult to solve the problem you've been experiencing. Would it be at all possible to post a gist/send me a small example that demonstrates the issue? I'm very keen to give this bug a good squashing, but it's eluding me!

All the best,
Al

@Jack-s
Copy link

Jack-s commented Aug 13, 2014

@alskipp
The problem still appears in the linked branch.

I modified the example to reproduce the issue, here's a link to the project

@alskipp
Copy link
Owner

alskipp commented Aug 13, 2014

Hi @Jack-s ,
Thanks for trying the other branch and for uploading the test project. I'll take a quick look and see if I can track down the issue. I'll have more time next week to investigate more deeply if needed. Hopefully, it'll be a simple fix : )

Al

@alskipp
Copy link
Owner

alskipp commented Aug 16, 2014

Hmmm, I'm now seeing this issue occur quite frequently on Xcode 6 (beta 5). In Xcode 5, it only seemed to occur in a few edge cases. Will investigate further.

@alskipp
Copy link
Owner

alskipp commented Apr 18, 2015

These issues seem to have been resolved when using the latest Xcode release (6.3). I'll close the issue for now on the assumption that all is well crossed fingers.

@alskipp alskipp closed this as completed Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants