Complete the code to animate a view's opacity change smoothly.
UIView.animate(withDuration: 1.0) { myView.alpha = [1] }
The alpha property controls opacity from 0 (transparent) to 1 (opaque). Using 0.5 fades the view to half transparency smoothly.
Complete the code to animate a view's position change using a spring effect.
UIView.animate(withDuration: 1.0, delay: 0, usingSpringWithDamping: [1], initialSpringVelocity: 0, options: [], animations: { myView.center.x += 100 }, completion: nil)
The damping ratio controls springiness. Values between 0 and 1 create a spring effect. 0.5 gives a nice bounce.
Fix the error in the animation block to correctly animate background color change.
UIView.animate(withDuration: 0.5) { myView.backgroundColor = [1] }
In Swift, UIColor.red is the correct way to access the red color. redColor() is Objective-C style and not valid here.
Fill both blanks to animate a view's scale transform to double size and back.
UIView.animate(withDuration: 0.3, animations: { myView.transform = CGAffineTransform.[1](x: 2.0, y: 2.0) }) { _ in UIView.animate(withDuration: 0.3) { myView.transform = CGAffineTransform.[2]() } }
Use CGAffineTransform.scale to enlarge the view, and CGAffineTransform.identity to reset it back to original size.
Fill all three blanks to animate a view's position, opacity, and background color change together.
UIView.animate(withDuration: 1.0) { myView.center.x += [1] myView.alpha = [2] myView.backgroundColor = UIColor.[3] }
Moving the view 100 points right, fading to 0.3 opacity, and changing background color to blue creates a smooth combined animation.