![](/img/trans.png)
[英]Lottie Animation: Stop Loop but wait until animation has finished
[英]How to wait until an animation is finished in Swift?
在我的測驗的下一個問題要加載之前,我試着讓按鈕“搖晃”。
動畫看起來像
var timer = NSTimer()
UIView.animateWithDuration(0.1, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
})
UIView.animateWithDuration(0.2, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x - 4, self.IMGVIEWcat.center.y)
})
UIView.animateWithDuration(0.3, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
})
在此之后調用以下函數
func QueryInformations(){
println("QueryInformationsStart")
self.ActivityIndicator.hidden = false
ObjectIDsArrayCount = ObjectIDsArray.count
var RandomQuestion = Int(arc4random_uniform(ObjectIDsArray.count + 0))
var QuestionID:String = ObjectIDsArray[RandomQuestion]
var query : PFQuery = PFQuery(className: "AddonQuiz")
query.getObjectInBackgroundWithId(QuestionID){
(ObjectHolder : PFObject!, error : NSError!) -> Void in
...
現在動畫開始但是下一個問題加載即時,是否有一些容易等待初學者實現“等待”直到動畫完成?
我試着設定
var complet == true
在動畫中
並在查詢功能
if complet = true {....
但這對我來說不起作用,我也發現了一些關於完成處理程序的信息,但是在我的代碼中沒有得到它。
如果要在動畫結束時使用completion
塊,則應使用帶有delay
和options
參數的構造。
UIView.animateWithDuration(0.3, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: {
// put here the code you would like to animate
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
}, completion: {(finished:Bool) in
// the code you put here will be compiled once the animation finishes
QueryInformations()
})
在您正在調用的函數上使用completion
塊:
UIView.animateWithDuration(0.3, animations: {
self.IMGVIEWcat.center = CGPointMake(self.IMGVIEWcat.center.x + 2, self.IMGVIEWcat.center.y)
}, completion: {(finished:Bool) in
QueryInformations()
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.