Skip to content
This repository has been archived by the owner on Jan 5, 2020. It is now read-only.

Animating Background Color Crashing #24

Closed
CharlesMassry opened this issue Sep 19, 2016 · 4 comments · Fixed by #25
Closed

Animating Background Color Crashing #24

CharlesMassry opened this issue Sep 19, 2016 · 4 comments · Fixed by #25

Comments

@CharlesMassry
Copy link
Contributor

When you use the method makeBackground with a basic default monotone colors that are created using the UIColor convenience methods, like UIColor.black, UIColor.white, UIColor.gray, etc., the app crashes because the way it finds the color components. In Swift 3 with iOS 10 these methods return a color with only two components, a darkness value and an alpha value. This does not cause an issue with colors like UIColor.red or UIColor(red: 0.0, blue: 0.0, green: 0.0, alpha: 1.0) however. I will be able to make a fix if you'd like.

@draveness
Copy link
Owner

That's great if you can open a PR 👍

@raulperez
Copy link

Hi.

This is still not fixed. I get a crash when trying to animate view's background color.

I have managed changing this code in DKKeyFrameAnimation:

    var valueArray: [Double] = []     ... to ...    var valueArray: [CGFloat] = []

and

     valueArray.append(value)  ... to ...  valueArray.append(CGFloat(value))
    fileprivate func valueArrayFor(startValue: CGFloat, endValue: CGFloat) -> NSArray {
        let startValue = Double(startValue)
        let endValue = Double(endValue)

        let steps: Int = Int(ceil(Double(kFPS) * self.duration)) + 2
        let increment = 1.0 / (Double)(steps - 1)
        var progress = 0.0
        var v = 0.0
        var value = 0.0

        var valueArray: [CGFloat] = []

        for _ in 0..<steps {
            v = self.functionBlock(self.duration * progress * 1000, 0, 1, self.duration * 1000);
            value = startValue + v * (endValue - startValue);

            valueArray.append(CGFloat(value))
            progress += increment
        }

        return valueArray as NSArray
    }

It could be possible to deploy a new version with a fix?

Thank you very much in advance.

@draveness
Copy link
Owner

@raulperez just released 2.0.1, but i don't know whether this could fix your bug or not.

@raulperez
Copy link

@draveness it doesn't. It continues crashing. If I apply the patch with the code I post over these comments it works again. But thank your for the help. Please, let me know when you have solved this issue. I will upgrade to the newest release again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants