UIView.animate(withDuration: 1) { self.view.backgroundColor = UIColor.darkGray }
And when you need a delay:
UIView.animate(withDuration: 4, delay: 5, options: [], animations: { self.view.backgroundColor = UIColor.darkGray }, completion: nil)
What can be animated?
Here are some common properties (but not all):- UIView.alpha - Use this to fade objects in or out. (Adjusts transparency)
- UIView.bounds - Defines the X,Y position of self (0,0) and the width, height of the object. Use to change the object's size or even position.
- UIView.center - Use to change the position of the object on the screen.
- UIView.frame - Defines the X,Y position inside its parent and the width, height of the object. Reposition or resize within a parent view.
- UIView.transform - Use this to rotate, scale, translate and skew objects.
- UIColor - Such as text color or background color. You can animate changing color such as in the example above.
- view.layoutIfNeeded() - Make changes to an object's constants and then call this function inside the animations block to see those changes animate.
(Swift 3)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.