如何使用不同的坐标重复动画

时间:2017-08-15 18:50:43

标签: ios swift animation

我尝试动画标签让它们一次又一次地进入随机坐标,但是当我跑步时,动画不会处理,即使我使用检查变量来确保动画是在确定其他坐标之前完成。 顺便说一句,如果您有任何想法来创建标签之间的互动,当它们碰到对方时,请写下来。

var check = 2
        var coordinateXLabel1 = 1
        var coordinateXLabel2 = 1
        var coordinateYLabel1 = 1
        var coordinateYLabel2 = 1
        while 1 == 1 {                     //create an infinit loop
            if check == 2{
                check = 0
                coordinateXLabel1 = Int(arc4random_uniform(324) + 25)
                coordinateXLabel2 = Int(arc4random_uniform(324) + 25)
                coordinateYLabel1 = Int(arc4random_uniform(560) + 111)
                coordinateYLabel2 = Int(arc4random_uniform(560) + 111)
                UIView.animate(withDuration: 1, animations: {
                    self.label1.center = CGPoint(x: coordinateXLabel1, y: coordinateYLabel1)
                }, completion: {(finished:Bool) in
                    check += 1
                })
                UIView.animate(withDuration: 1, animations: {
                    self.label2.center = CGPoint(x: coordinateXLabel2, y: coordinateYLabel2)
                }, completion: {(finished:Bool) in
                    check += 1
                })
            }
        }

1 个答案:

答案 0 :(得分:0)

使用此代码 -

length = []

class_one = [1, 2, 3]

class_two = ['one', 'two', 'three']

for x in class_one:

    if x < 4:

        length[class_two] = class_one

print(length)