I'm trying to change the color of a button's background using the cross dissolve animation, however, whenever I run this it instantly change the color instead of having a smooth transition.
UIView.transition(with: self.SignIn,
duration:3,
options: UIViewAnimationOptions.transitionCrossDissolve,
animations: { self.SignIn.backgroundColor? = UIColor(hexaString: "#" + hex) },
completion: nil)
Instead of setting backgroundColor in animations block I have set it before the view transition and then start the transition of view and it will work perfectly.
self.btnAnimate.backgroundColor = UIColor.red
UIView.transition(with: self.btnAnimate,
duration: 3,
options: .transitionCrossDissolve,
animations: nil,
completion: nil)
Output

Note: I have set red color as backgroundColor you can set what ever color you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With