TypeError: res.send is not a function
这里的问题是,在动画完成之前,最终结果显示得太快。动画 @IBAction func rollButtonPressed(_ sender: UIButton) {
animateImages()
displayFinalOutcome()
}
应用于UIImage.animatedImage
。
有没有办法延迟调用" displayFinalOutcome" ?
我花了不少于一个小时的时间。任何建议都非常感谢。
答案 0 :(得分:1)
您可以在动画后执行displayFinalOutcome()
中的DispatchQueue
。
喜欢这样:
这里0.5
是秒,它可以是你的图像动画持续时间。
@IBAction func rollButtonPressed(_ sender: UIButton) {
animateImages()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.displayFinalOutcome()
}
}
答案 1 :(得分:1)
我认为最好使用处理程序。像这样:
@IBAction func rollButtonPressed(_ sender: UIButton) {
animateImages { (complete) in
displayFinalOutcome()
}
}
func animateImages(completion: ((Bool) -> ())) {
// code of your method
completion(true)
}
<强>更新强>
animateImages()方法中的示例:
func animateImages(completion: ((Bool) -> ())) {
// code of your method
UIView.animate(withDuration: yourTimeInterval, animations: {
// code of your animations
}) { (complete) in
completion(true)
}
}
这里你的方法displayFinalOutcome()只能在动画完成后才能应用
答案 2 :(得分:0)
试试这个:
@IBAction func rollButtonPressed(_ sender: UIButton) {
animateImages()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { // change 2 to desired number of seconds
// Your code with delay
self.displayFinalOutcome()
}
}
希望这会有所帮助。