Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a UIView fade from a solid background color to clear background color?

Tags:

ios

swift

I know that there are multiple ways (CAAnimation, commitAnimations, etc), but what is the simplest way?

I'd like the UIView to start from blue and then fade to clear (or white, whatever is easier) in X milliseconds.

like image 882
TIMEX Avatar asked May 04 '16 22:05

TIMEX


1 Answers

You can use UIView's animation method. It's much simpler than the other animations, but is more limited. Luckily, backgroundColor is one of the animatable ones. Example:

self.view.backgroundColor = UIColor.blueColor()

UIView.animateWithDuration(1.0, animations: {
    self.view.backgroundColor = UIColor.clearColor()
})
like image 107
brimstone Avatar answered Nov 20 '22 13:11

brimstone