Swift 3 - 延迟重复动画
Swift 3 - Delay Repeating Animation
目前,此动画每 3 秒重复一次。我希望在重复此动画之间有 10 秒的等待时间。我怎样才能做到这一点?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 7.5, delay: 20,
options: .repeat,
animations: {
self.imageAnimate.center.x += self.view.bounds.width * 2
},
completion: nil
)
}
使用 Timer
:
// note that I used 17.5 here because the animation itself takes 7.5 seconds
// so that will be 7.5 seconds of animating, 10 seconds of doing nothing
// and start animating again
Timer.scheduledTimer(withTimeInterval: 17.5, repeats: true) {
UIView.animate(withDuration: 7.5, animations: {
self.imageAnimate.center.x += self.view.bounds.width * 2
})
}
目前,此动画每 3 秒重复一次。我希望在重复此动画之间有 10 秒的等待时间。我怎样才能做到这一点?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 7.5, delay: 20,
options: .repeat,
animations: {
self.imageAnimate.center.x += self.view.bounds.width * 2
},
completion: nil
)
}
使用 Timer
:
// note that I used 17.5 here because the animation itself takes 7.5 seconds
// so that will be 7.5 seconds of animating, 10 seconds of doing nothing
// and start animating again
Timer.scheduledTimer(withTimeInterval: 17.5, repeats: true) {
UIView.animate(withDuration: 7.5, animations: {
self.imageAnimate.center.x += self.view.bounds.width * 2
})
}