Complete the code to create a basic UIView animation with a duration of 2 seconds.
UIView.animate(withDuration: [1]) { myView.alpha = 0 }
The withDuration parameter sets how long the animation lasts in seconds. Here, 2.0 means the animation will take 2 seconds.
Complete the code to use a custom timing curve with UIViewPropertyAnimator.
let animator = UIViewPropertyAnimator(duration: 1.5, curve: [1]) { myView.frame.origin.x += 100 } animator.startAnimation()
The .easeInOut curve makes the animation start slow, speed up, then slow down at the end, creating a smooth effect.
Fix the error in the code to create a custom timing curve using CAMediaTimingFunction.
let timingFunction = CAMediaTimingFunction(controlPoints: [1], 0.0, 1.0, 1.0) let animation = CABasicAnimation(keyPath: "position.x") animation.timingFunction = timingFunction
The controlPoints initializer expects four Float values. The first two are the x and y of the first control point. Here, the first two values must be separated by commas and there should be exactly four values total.
Fill both blanks to create a UIViewPropertyAnimator with a custom cubic timing curve and start it.
let timing = UICubicTimingParameters(controlPoint1: CGPoint(x: [1], y: [2])) let animator = UIViewPropertyAnimator(duration: 1.0, timingParameters: timing) animator.startAnimation()
The control points define the shape of the cubic Bezier curve. Common values like (0.25, 0.75) create a smooth ease-in-out effect.
Fill all three blanks to create a CABasicAnimation with a custom timing function and add it to a layer.
let animation = CABasicAnimation(keyPath: "opacity") animation.fromValue = [1] animation.toValue = [2] animation.timingFunction = CAMediaTimingFunction(name: [3]) myLayer.add(animation, forKey: "fade")
The animation fades opacity from 1.0 (fully visible) to 0.0 (invisible). The timing function easeInEaseOut makes the fade smooth.