thomasfinch / GammaThingy

Changes screen gamma on iOS, no jailbreak required
777 stars 94 forks source link

Transition animation #41

Open ANGOmarcello opened 9 years ago

ANGOmarcello commented 9 years ago

Hey folks what do you think about this? I worked on a little method to transition between gamma values.

// This method creates a transistion from one gamma value to another
+ (void)setGammaWithTransitionFrom:(float)oldPercentOrange to:(float)newPercentOrange {

    float delay = 0.02; // The animation delay

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        if (newPercentOrange > oldPercentOrange) {
            for (float i = oldPercentOrange; i <= newPercentOrange; i = i + 0.01) {
                [NSThread sleepForTimeInterval:delay];
                [self setGammaWithOrangeness:i];
                NSLog(@"%f",i);
            }
        } else {
            for (float i = oldPercentOrange; i >= newPercentOrange; i = i - 0.01) {
                [NSThread sleepForTimeInterval:delay];
                [self setGammaWithOrangeness:i];
                NSLog(@"%f",i);
            }
        }
    });
}
ANGOmarcello commented 9 years ago

So far I have implemented this into my branch successfully. Now I'm trying to improve it in a way wich makes it im possible to have two transition running at the same time. Handling these transitions with a NSTimer could be the solution.

CasperCL commented 9 years ago

Looks great, but why do you want to be able to play multiple transitions at the same time?

ANGOmarcello commented 9 years ago

No I don’t want to do that. :D

It’s more like that: If you hammer the enabled button it will play multiple transitions at once. Just thinking about a way to cancel the last transition so that this does not happen. :)

Am 23.10.2015 um 11:04 schrieb Casper notifications@github.com:

Looks great, but why do you want to be able to play multiple transitions at the same time?

— Reply to this email directly or view it on GitHub https://github.com/thomasfinch/GammaThingy/issues/41#issuecomment-150521063.

arthurhammer commented 9 years ago

I'm currently playing with a Today Widget and this is indeed an issue there. The widget has an enable/disable toggle, an increase (orangeness) and a decrease button. When you hit "enable" but do "increase/decrease" before the transition is finished, it flickers badly and it ends in an inconsistent state at the end. It's not that bad in the main app, but in the widget it's very noticeable.

ANGOmarcello commented 9 years ago

I understand well for now you should stick with that because we could implement a better transition logic in the ganma controller later. I will do that but at the moment time is rare.

If you want to improve it yourself: Using an NSTimer to trigger the transition and invalidating it if another animation is triggered should do the job. Also it would be smart to have a variable wich saves the last state of your animation so that if you have to abort an animation you can use the last current value to transition in the new direction.

Am 27.10.2015 um 19:01 schrieb Arthur Hammer notifications@github.com:

I'm currently playing with a Today Widget and this is indeed an issue there. The widget has an enable/disable toggle, an increase (orangeness) and a decrease button. When you hit "enable" but do "increase/decrease" before the transition is finished, it flickers badly and it ends in an inconsistent state at the end. It's not that bad in the main app, but in the widget it's very noticeable.

— Reply to this email directly or view it on GitHub.