Use the following code snippet to create a repeated animation

Create Repeated Animation

Use the following code snippet to create a repeated animation

1
2
3
4
5
6
7
// set original state
UIView.animate(withDuration: 0.4,
delay: 0.0,
options: [.repeat, .autoreverse],
animations: { [unowned self] in
// set animated state
}, completion: nil)

Note that we should define this animation in viewWillAppear instead of viewDidLoad if we want to reuse the view and keep animation display on screen. Because animation will stopped once view gets disappear.