UIImageView圖像動畫沒有「完成處理程序」。它比這更簡單。
如果您想要完成處理程序,請使用某種具有完成處理程序的動畫。 (你的情況,我不明白爲什麼你甚至需要一個完成處理程序,你知道什麼時候這個動畫會結束:從現在起第二秒,所以只需設置一個NSTimer來回叫你) 所以你的代碼將是:
func showButton(timer : NSTimer) {
YourButtonOutlet.enabled = true
//this will enable you button again
}
@IBAction func btn_LeeStatue(sender: AnyObject) {
lee_statue_img.animationImages = [
UIImage(named: "lee_statueAni0001.png")!,
UIImage(named: "lee_statueAni0002.png")!,
UIImage(named: "lee_statueAni0003.png")!,
UIImage(named: "lee_statueAni0004.png")!,
UIImage(named: "lee_statueAni0005.png")!,
]
//Disable the button
YourButtonOutlet.enabled= false
lee_statue_img.animationDuration = 3
lee_statue_img.animationRepeatCount = 1
lee_statue_img.startAnimating()
//set the timer for X seconds (4s in this example)
let myTimer : NSTimer = NSTimer.scheduledTimerWithTimeInterval(4, target: self, selector: Selector("showButton:"), userInfo: nil, repeats: false)
}
,您還可以使用調度後, 只需添加這個功能 - >
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
,你可以這樣調用 - >(0.75是時間的應用在執行封閉之前應該等待什麼)
delay(0.75, closure: {
//write here the code to be executed after 0.75 second
//in your case it will be YourButtonOutlet.enabled = true
})
PS:你必須設置YourButtonOutlet.enabled = false
動畫開始
感謝您的意見Mr.Abida,但我想更簡單的代碼..有沒有辦法更簡單的代碼?我不想使用NSTimer ..; - > – Kyu
相信我,使用NSTimer是最簡單的方法,如果你想使用完成處理程序(在動畫完成時得到通知,你必須使用另一種動畫) –
In這個時代,我會選擇'dispatch_after()'而不是'NSTimer' ...(我的意見) –