-
Notifications
You must be signed in to change notification settings - Fork 3
iOS Animations
Kevin Leong edited this page Nov 28, 2016
·
5 revisions
UIView.animateKeyframes(withDuration: 2, delay: 0, options: [.repeat, .autoreverse, .calculationModePaced], animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
spinner.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI * 2)/3)
spinner.backgroundColor = UIColor.blue
}
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
spinner.transform = CGAffineTransform(rotationAngle: 2*CGFloat(M_PI * 2)/3)
spinner.backgroundColor = UIColor.green
}
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0) {
spinner.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI * 2))
spinner.backgroundColor = UIColor.red
}
}, completion: nil)
(void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
usingSpringWithDamping:(CGFloat)dampingRatio
initialSpringVelocity:(CGFloat)velocity
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion;
parameter | description | values |
---|---|---|
duration | How long the animation should take, in seconds. | if <= 0 , no animation will be applied |
dampingRatio | Amount of bouncing desired. | Use 1 to smoothly decelerate with no oscillation. Values closer to 0 will increase oscillation/bouncing. The higher the value, the faster the oscillations will cease. |
velocity | The spring's initial velocity. The damping ratio will proportionally decrement this value until the velocity reaches 0. | Higher values will increase the oscillations speed. |
- Apple Developer
- How to animate views with spring damping - Hacking with Swift