popViewController的完成块 [英] Completion block for popViewController

查看:381
本文介绍了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?

完成参数相当方便。例如,我可以使用它来阻止从表格视图中删除一行,直到模态在屏幕外,让用户看到行动画。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆