【发布时间】:2016-05-19 03:33:33
【问题描述】:
我有以下小功能,其中包含我希望发生的两个主要操作。三秒钟的动画,然后在该动画完成后,另一个函数调用。然而,发生的情况是调用另一个函数的代码行在 UIView 动画完成之前正在执行。
func switchToNormalState() {
print("Switching to Normal State")
currentState = "normal"
intervalCounter = intervalCounter + 1
setVisualsForState()
UIView.animateWithDuration(Double(normalDuration), animations: { () -> Void in
self.ProgressBar.setProgress(1.0, animated: true)
}, completion: { _ in
self.switchToFastState()
})
}
我研究了其他类似的帖子以寻找解决方案,但没有一个解决方案能够解决我的难题。为了使这些动作成为顺序而不是同时发生,我在完成块中做错了什么?
【问题讨论】:
-
我认为发生这种情况是因为 progressBar 也有动画,所以我认为一旦动画块运行,完成块就会执行。但是由于进度条处于动画过程中,所以功能运行得很快。
-
@ChathurangaSilva 所说的是正确的。你为什么要为此使用 UIView 动画块?进度条有自己的动画。
标签: swift uiview animatewithduration completion