UIView's background color keeps reverting back to original color upon completion

180 Views Asked by At

Is there any reason why the backgroundColor of a UIView would jump back to its original color after changing it's color property in a nested UIView.animate method? I set it to clear during the animation then it jumps back to white upon my last second to last completion.

I have tried converting over to animateWithKeyframes and I still have a similar condition.

Basically I am trying to use a view as a mask and animate it across a label. I have a darkModeBool that indicates if the user wants a dark theme. I want the label.textColor and the view.Background color to change accordingly to my set theme protocol when it hits that animation block if that darkModeBool is set to true.

func animateGraphic() {
    firstMaskWidthConstraint.constant = 0
    UIView.animate(withDuration: 1.2, delay: 1, options: .curveLinear, animations: {
        self.view.layoutIfNeeded()
        self.firstMaskView.backgroundColor = .clear
        print("1")
    }) { (_) in
        self.secondMaskHeightConstraint.constant = 0
        UIView.animate(withDuration: 0.8, delay: 0, options: .curveEaseIn, animations: {
            self.view.layoutIfNeeded()
            self.secondMaskView.backgroundColor = .clear
            print("2")
        }, completion: { (_) in
            UIView.animate(withDuration: 1, delay: 0.8, options: .curveEaseInOut, animations: {
                self.view.layoutIfNeeded()
                self.view.backgroundColor = SproutTheme.current.backgroundColor.cgColor
                self.sproutLabel.textColor = SproutTheme.current.textColor

            }, completion: { (_) in
                RunLoop.current.run(until: Date(timeIntervalSinceNow: 1.8))
                self.popToNavigationStack()
            })
        })
    }
}

When the view is supposed to change it's backgroundColor in the second to last completion, the firstMaskView and secondMaskView go back to white covering the text. Any input is greatly appreciated.

0

There are 0 best solutions below