[英]Swift Animations - Perform a sequence
I'm not entirely sure how to perform a sequence of animations. 我不确定如何执行一系列动画。 If I try this it normally skips to the last one in the function.
如果我尝试这样做,通常会跳到函数中的最后一个。
Let's say I want to move 2 UIImageView
(side-by-side) 300 points upwards, then 2 UILabel
(below the UIImageView
) 300 points upwards as well. 假设我要向上移动2个
UIImageView
(并排)300点,然后也向上移动2个UILabel
(位于UIImageView
下方)。
Then, I want the Label to count up from 1 to 10 -for example-. 然后,我希望Label从1到10递增计数-例如-。
Finally, once the label has counted to 10, I want the UIImageView
and UILabel
to move back down by 300 points. 最后,一旦标签计数到10,我希望
UIImageView
和UILabel
向下移动300点。
func moveLabelUP() {
label.center = CGPoint(x: label.center.x - 300, y: label.center.y)
UILabel.animate(withDuration: 5) {
self.label.center = CGPoint(x: self.label.center.x + 300, y: self.label.center.y)
func startLabelCountUp(){
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateLabel), userInfo: nil, repeats: true)
}
func updateLabel(){
if self.current < elapsedTime {
self.current += 1
self.label.text = "\(self.current)"
}else{
self.timer.invalidate()
}
}
How can I connect these chain of events? 如何连接这些事件链?
How can I apply a delay to when the timer starts for each UILabel
? 如何为每个
UILabel
的计时器启动时间设置延迟?
I want the UIImageView
to raise, the UILabel
counts to 10, Then the UIImageView
is lowered. 我希望提高
UIImageView
,将UILabel
计数为10,然后降低UIImageView
。 This should repeated for the next UIImageView
and UILabel
to the right of the first ones. 对于第一个右侧的下一个
UIImageView
和UILabel
,应重复此操作。
This is the way I have been using it. 这就是我一直在使用它的方式。 It is just a basic concept but you will get an idea.
这只是一个基本概念,但您会有所想法。 For my case I was using it with constants.
就我而言,我在常量中使用它。
UIView.animate(withDuration: duration, animations: {
// Your changes to the UI, eg. moving UIImageView up 300 points
}) { (success) in
// This executes when animation is completed
// Create another animation here. It starts when previous ends
UIView.animate(withDuration: duration2, animations: {
// Your changes to the UI
}, completion: { (success) in
// This executes when animation is completed
})
})
Also check other frameworks that could help you, there are a few good ones. 还要检查其他可以帮助您的框架,这里有一些不错的框架。 I tried Cheetah which supports chaining animations and works really well.
我尝试了Cheetah ,它支持链接动画并且效果很好。
Just ask if you have any questions. 只要问您有什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.