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

Background Color Animation #1683

Closed
RodolfoAntonici opened this issue Jul 1, 2015 · 3 comments
Closed

Background Color Animation #1683

RodolfoAntonici opened this issue Jul 1, 2015 · 3 comments

Comments

@RodolfoAntonici
Copy link

Hey there,
Im having an issue with the IFTTTColorAnimation

    var gradientBarColorAnimation: IFTTTColorAnimation!

    public override func viewDidLoad() {
        super.viewDidLoad()

        var myView = UIView(frame: CGRectMake(0, 0, 100, 100));
        myView.backgroundColor = UIColor.blackColor()
        self.view.addSubview(myView)

        self.gradientBarColorAnimation = IFTTTColorAnimation(view: myView)
        self.gradientBarColorAnimation.addKeyframeForTime(0, color: myView.backgroundColor)
        self.gradientBarColorAnimation.addKeyframeForTime(64, color: UIColor.redColor())
    }

    public func scrollViewDidScroll(scrollView: UIScrollView) {

        self.gradientBarColorAnimation.animate(scrollView.contentOffset.y)
    }

The problem is: when it pass the 64 time, it just changes the color to red, isn't an animated transition.
I tried to change the colors alpha chanel as the example uses, it doesn't work either.

Aditional info:
iOS 8.4,
Xcode 6.4
Swift 1.2

@gazsp
Copy link

gazsp commented Jul 7, 2015

I have the same issue with JazzHands 2.0, although the demo app works fine.

scrollViewDidScroll uses the default implementation from IFTTTAnimatedPagingScrollViewController.

@gazsp
Copy link

gazsp commented Jul 7, 2015

The issue is in IFTTTFilmStrip.m here (see the commented out line):

- (id<IFTTTInterpolatable>)valueAtTime:(CGFloat)time
{
    NSAssert(!self.isEmpty, @"At least one KeyFrame must be set before animation begins.");
    id value;
    NSUInteger indexAfter = [self indexOfKeyframeAfterTime:time];
    if (indexAfter == 0) {
        value = ((IFTTTKeyframe *)self.keyframes[0]).value;
    } else if (indexAfter < self.keyframes.count) {
        IFTTTKeyframe *keyframeBefore = (IFTTTKeyframe *)self.keyframes[indexAfter - 1];
        IFTTTKeyframe *keyframeAfter = (IFTTTKeyframe *)self.keyframes[indexAfter];
        CGFloat progress = [self progressFromTime:keyframeBefore.time toTime:keyframeAfter.time atTime:time withEasingFunction:keyframeBefore.easingFunction];
        if ([keyframeBefore.value respondsToSelector:@selector(interpolateTo:withProgress:)]
//            && [keyframeAfter.value isKindOfClass:[keyframeBefore.value class]]
        ) {
            value = [keyframeBefore.value interpolateTo:keyframeAfter.value withProgress:progress];
        } else {
            value = keyframeBefore.value;
        }
    } else {
        value = ((IFTTTKeyframe *)self.keyframes.lastObject).value;
    }
    return value;
}

This is because [UIColor blackColor] has a class of UIDeviceWhiteColor, where as any other non white / black / grey colours will have a class of UIDeviceRGBColor. This makes the if statement fail, and hence the interpolation.

@lauraskelton
Copy link
Contributor

@RodolfoAntonici Thanks for pointing out the issue, and @gazsp thanks for the super helpful detective work on the cause!

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