Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-Disolve transition just changes instantly - Swift 3.0

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)
like image 798
Max Kortge Avatar asked Dec 21 '25 16:12

Max Kortge


1 Answers

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

enter image description here

Note: I have set red color as backgroundColor you can set what ever color you want.

like image 124
Nirav D Avatar answered Dec 24 '25 06:12

Nirav D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!