如何在iOS中重置动画?

时间:2017-03-24 02:04:29

标签: ios swift uiviewanimation

这是我的代码:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    cloud.center.x  -= view.bounds.width
    cloud1.center.x -= view.bounds.width
    cloud2.center.x -= view.bounds.width
    cloud3.center.x -= view.bounds.width
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    UIView.animate(withDuration: 12) {
        self.cloud.center.x += self.view.bounds.width*2

        UIView.animate(withDuration: 12, delay: 9, options: [],
                       animations: {
                            self.cloud1.center.x += self.view.bounds.width*2
                        },
                       completion: nil
        )
        UIView.animate(withDuration: 12, delay: 18, options: [],
                       animations: {
                            self.cloud2.center.x += self.view.bounds.width*2
                        },
                       completion: nil
        )
        UIView.animate(withDuration: 12, delay: 22, options: [],
                       animations: {
                            self.cloud3.center.x += self.view.bounds.width*2
                        },
                       completion: nil
        )
    }
}

我有一个重做,重新设置页面中的所有内容,除了我的动画只停留在一个位置。如何重置动画以便再次重新播放动画?

1 个答案:

答案 0 :(得分:0)

您的动画代码会将{4}云视图向右移动self.view.bounds.width*2,将该数量添加到其中心位置。

要撤消该更改,只需减去相同的金额。