2017-01-22 68 views
0

我需要幫助,因爲我找不到任何示例來完成我想要的任何地方。Swift 3 - performSegue當動畫序列停止

我想一旦它完成動畫一個簡單的PNG序列,然後再打一個performSegue(這是我的主要問題)

所以我

InitImage.animationImages = [ 
    UIImage(named:"load1.png")!, 
    UIImage(named:"load2.png")!, 
    UIImage(named:"load3.png")!, 
/* 20 more images... */ 
] 

InitImage.animationDuration = 2.5 
InitImage.animationRepeattCount = 1 
InitImate.startAnimating() 

試圖所以動畫,但太早打電話SEGUE 。我發現我可能應該使用

UIView.animate(withDuration : ...) 

但我找不到一個用Swift3編寫的動畫文件序列的例子。

有人能告訴我方式嗎? 謝謝。

+1

我不認爲有一個UIView animateWithDuration變體,可以讓你循環一系列靜態圖像,如動畫GIF。你必須使用你當前使用的代碼。 Axel的解決方案是創建一個計時器,以計算誰的持續時間,以便在動畫完成時觸發,這可能是最好的方法。 –

回答

1

我認爲最簡單的方法是讓一個計時器

Timer.scheduledTimer(timeInterval: InitImage.animationDuration * Double(InitImage.animationImages?.count ?? 0), target: self, selector: #selector(push), userInfo: nil, repeats: false) 

和選擇

func push() { 
.... perform segue 
} 
1

最簡單的方法是使用performSelector與afterDelay,因爲自我是一個@objc的UIViewController:

self.perform(#selector(segueToDetailViewController), with: self, afterDelay: InitImage.animationDuration) 

和選擇:

func segueToDetailViewController() { 
    self.performSegue(... etc ...) 
} 

上面的代碼不會將動畫持續時間乘以圖像數量,因爲當我運行代碼時,我發現所有圖像的動畫持續時間爲2.5秒。