Wave
public class Wave
-
Performs animations based on the
Springvalue provided.Note: For animations to work correctly, you must set values on the view’s
animator, not just the view itself. For example, to animate a view’s alpha, usemyView.animator.alpha = 1.0instead ofmyView.alpha = 1.0.For a full list of the various
UIViewandCALayeranimatable properties that Wave supports, seeViewAnimatorandLayerAnimator.Example Usage:
let box = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) view.addSubview(box) box.backgroundColor = .systemMint Wave.animateWith(spring: Spring(dampingRatio: 0.6, response: 1.2)) { // Animate some `UIView` properties box.animator.center = view.center box.animator.backgroundColor = .systemBlue // And one on `CALayer` box.layer.animator.cornerRadius = 10.0 }Declaration
Swift
public static func animate( withSpring spring: Spring, mode: AnimationMode = .animated, delay: TimeInterval = 0, gestureVelocity: CGPoint? = nil, animations: (() -> Void), completion: ((_ finished: Bool, _ retargeted: Bool) -> Void)? = nil)Parameters
springThe
Springused to determine the timing curve and duration of the animation. See the initializerSpring(dampingRatio:response:mass)for more information on how to choose relevant spring values.modeOptional. Determines if the
animationsblock will be run with animation (default), or non-animatedly. SeeAnimationModefor information on when to use a non-animated mode.delayOptional. A delay, in seconds, after which to start the animation.
gestureVelocityOptional. If provided, this value will be used to set the
velocityof whatever underlying animations run in theanimationsblock. This should be primarily used to “inject” the velocity of a gesture recognizer (when the gesture ends) into the animations.animationsA block containing the changes to your views’ animatable properties. Note that for animations to work correctly, you must set values on the view’s
animator, not just the view itself. For example, to animate a view’s alpha, usemyView.animator.alpha = 1.0instead ofmyView.alpha = 1.0.completionA block to be executed when the specified animations have either finished or retargeted to a new value.
Wave Class Reference