您应该为此使用关键帧动画,因为它允许您指定动画的顺序。下面是一个基本示例:
let animationDuration = 2.0
let position: CGFloat = 50.0
let viewToAnimate = UIImageView()
UIView.animateKeyframes(withDuration: animationDuration, delay: 0.0, options: .calculationModeLinear, animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/3, animations: {
viewToAnimate.frame.origin.y = viewToAnimate.frame.origin.y + position
})
UIView.addKeyframe(withRelativeStartTime: 1/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.y = viewToAnimate.frame.origin.y - (position * 2)
})
UIView.addKeyframe(withRelativeStartTime: 2/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.x = viewToAnimate.frame.origin.x - position
})
UIView.addKeyframe(withRelativeStartTime: 3/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.x = viewToAnimate.frame.origin.x + (position * 2)
})
}, completion: { completed in
})