2017-01-22 72 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秒。