popViewController 的完成块 [英] Completion block for popViewController
问题描述
当使用 dismissViewController
关闭模态视图控制器时,可以选择提供一个完成块.popViewController
是否有类似的等价物?
When dismissing a modal view controller using dismissViewController
, there is the option to provide a completion block. Is there a similar equivalent for popViewController
?
完成参数非常方便.例如,我可以使用它来推迟从 tableview 中删除一行,直到模态离开屏幕,让用户看到行动画.从推送的视图控制器返回时,我希望有同样的机会.
The completion argument is quite handy. For instance, I can use it to hold off removing a row from a tableview until the modal is off screen, letting the user see the row animation. When returning from a pushed view controller, I would like the same opportunity.
我尝试将 popViewController
放在 UIView
动画块中,在那里我可以访问完成块.但是,这会对弹出的视图产生一些不需要的副作用.
I have tried placing popViewController
in an UIView
animation block, where I do have access to a completion block. However, this produces some unwanted side effects on the view being popped to.
如果没有这样的方法可用,有哪些解决方法?
If there is no such method available, what are some workarounds?
推荐答案
我知道一个答案已经在两年多前被接受了,但是这个答案是不完整的.
I know an answer has been accepted over two years ago, however this answer is incomplete.
没有办法做你想做的开箱即用
There is no way to do what you're wanting out-of-the-box
这在技术上是正确的,因为 UINavigationController
API 没有为此提供任何选项.但是,通过使用 CoreAnimation 框架,可以向底层动画添加完成块:
This is technically correct because the UINavigationController
API doesn't offer any options for this. However by using the CoreAnimation framework it's possible to add a completion block to the underlying animation:
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// handle completion here
}];
[self.navigationController popViewControllerAnimated:YES];
[CATransaction commit];
一旦 popViewControllerAnimated:
使用的动画结束,将立即调用完成块.此功能从 iOS 4 开始可用.
The completion block will be called as soon as the animation used by popViewControllerAnimated:
ends. This functionality has been available since iOS 4.
这篇关于popViewController 的完成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!