3

画面に順番に表示しようとしているボタンの IBOutlet コレクションがあります。それらはすべて画面から正常に開始されますが、アニメーションが開始されると、各ボタンが前のボタンの 0.05 秒後に画面に表示されるようにしたいと思います。UIView.animateWithDuration で遅延を増やす方法がわかりません。以下のコードでは、それらはすべて画面上で同時にアニメーション化されています。

//outlet collection
@IBOutlet var options: [UIButton]!

let increment = 0.25

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

    for button in options {
        button.center.y += view.bounds.height
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    for button in options {
        UIView.animateWithDuration(1.0, delay: increment, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: nil, animations: {
            button.center.y -= self.view.bounds.height
            self.increment + 0.05
            }, completion: nil)
    }
}
4

3 に答える 3

1
for button in options {
        UIView.animateWithDuration(1.0, delay: increment, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: nil, animations: {
            button.center.y -= self.view.bounds.height
            }, completion: nil)

    }
           increment = increment + 0.05

}

その他: これを変更

let increment = 0.25

   var increment = 0.25

increment外側のアニメーションを増やします。animateWithDurationは非同期メソッドであるため、最初に が返されます。したがって、すべてのボタンの遅延は同じです。

于 2015-05-06T02:04:26.183 に答える
-1

アニメーション間に必要な遅延を達成する方法は次のとおりです。

var i! as UInt64;
i = 0
for button in options {
                // your animation with delay
        UIView.animateWithDuration(1.0, delay: (i *0.05), usingSpringWithDamping: 0.7, initialSpringVelocity: 0.0, options: nil, animations: {
            button.center.y -= self.view.bounds.height
            }, completion: nil)
    })
    ++i

}
于 2015-05-06T06:14:36.887 に答える