Wave
public class Wave
-
Performs animations based on the
Spring
value 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.0
instead ofmyView.alpha = 1.0
.For a full list of the various
UIView
andCALayer
animatable properties that Wave supports, seeViewAnimator
andLayerAnimator
.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
spring
The
Spring
used 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.mode
Optional. Determines if the
animations
block will be run with animation (default), or non-animatedly. SeeAnimationMode
for information on when to use a non-animated mode.delay
Optional. A delay, in seconds, after which to start the animation.
gestureVelocity
Optional. If provided, this value will be used to set the
velocity
of whatever underlying animations run in theanimations
block. This should be primarily used to “inject” the velocity of a gesture recognizer (when the gesture ends) into the animations.animations
A 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.0
instead ofmyView.alpha = 1.0
.completion
A block to be executed when the specified animations have either finished or retargeted to a new value.