【发布时间】:2019-06-16 02:06:54
【问题描述】:
我想等到关闭动画完成,但我不想在我的代码中使用很多块,所以我在UIViewControllerextension 中编写了这个函数(几年前对我来说几乎就像这样):
func dismissAnimated() {
var comleted: Bool = false
self.dismiss(animated: true) {
comleted = true
}
while !comleted {
RunLoop.current.run(mode: RunLoop.Mode.common, before: Date.distantFuture)
}
}
所以现在而不是:
viewController.dismiss(animated: true) {
// code after completion
}
我应该写:
viewController.dismissAnimated()
// code after completion
但它不会关闭视图控制器,也不会进入完成块。
我尝试了不同的 RunLoop 模式,尝试了不同的日期,尝试将 RunLoop.current.run 插入 while 条件,但没有成功。任何想法如何做到这一点?
编辑:
它可以在 iOS 9 或类似的系统上运行(可能有一些代码更改,因为我找不到我的源代码)。我启动RunLoop.current.run 以避免阻塞主线程。例如,如果我将 completed = true 放入 DispatchQue.main.asyncAfter ,它将起作用,问题在于 dismiss
【问题讨论】:
标签: ios iphone swift uiviewcontroller runloop