How to make this complex animation repeat and autoreverse? Is there any way to add options UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat to this animation s
Swift 4 for simple wiggle sequence:
func animateWiggle() {
// Set animation props
let scaleDelta = CGFloat(0.10)
// Set transforms
let wiggleOutHorizontally = CGAffineTransform(scaleX: 1.0 + scaleDelta, y: 1.0)
let wiggleOutVertically = CGAffineTransform(scaleX: 1.0, y: 1.0 + scaleDelta)
// Run animation sequence
UIView.animateKeyframes(withDuration: 1.0, delay: 0.0, options: [.autoreverse, .repeat], animations: {
// Animate wiggle horizontally
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5, animations: {
self.transform = wiggleOutHorizontally
})
// Animate wiggle vertically
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: {
self.transform = wiggleOutVertically
})
},
completion: nil)
}