Swift动画 - 执行序列

时间:2016-10-05 06:51:23

标签: ios swift animation

我不完全确定如何执行一系列动画。如果我试试这个,它通常会跳到函数中的最后一个。

让我们说我要向前移动2 UIImageView(并排)300点, 然后2 UILabel(低于UIImageView)300点以上。

然后,我希望Label从1到10计数 - 例如 - 。

最后,一旦标签数量达到10,我希望UIImageViewUILabel向下移动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()
    }
}

如何连接这些事件链?

如何为每个UILabel计时器启动延迟时间?

我希望UIImageView加注,UILabel计数到10,然后降低UIImageView。这应该在第一个UIImageViewUILabel的右边重复。

1 个答案:

答案 0 :(得分:2)

这是我使用它的方式。这只是一个基本概念,但你会得到一个想法。对于我的情况,我使用它与常量。

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

            })

})

同时检查可以帮助您的其他框架,有一些好的框架。我尝试Cheetah支持链接动画并且效果很好。

请问您是否有任何问题。