在UINavigationController推送/弹出过渡期间允许用户交互

时间:2018-12-17 16:45:14

标签: ios swift iphone-privateapi

由于在进行推入/弹出操作时我们无法控制动画调用(即使通过子类化UINavigationController),所以我们无法使用.allowUserInteraction方法的UIView.animate选项。

但是在看了https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.waitall?view=netframework-4.7.2之后,我发现Apple确实通过提供私有API和私有标志(allowUserInteractionDuringTransition)考虑了这种用例(至少从iOS 8开始)。因此,必须有一种方法允许导航控制器允许用户交互。

如何??

2 个答案:

答案 0 :(得分:3)

您为什么要为此使用私有API?

您可以通过公共UIViewControllerTransitioningDelegate API来实现交互式的推送和弹出过渡。只要您使用UIView.animate*方法,它就非常容易并且免费提供大多数交互功能。 UIPercentDrivenInteractiveTransition消除了大多数困难,您甚至可以使用UIDynamicAnimator获得酷似流体的效果。

您可以通过这种方式很容易地实现系统转换。无论如何,您都可以通过滑动以返回免费获得弹出过渡-只需按一下即可。

以下是一些示例:

https://theswiftdev.com/2018/04/26/ios-custom-transition-tutorial-in-swift/

https://www.raywenderlich.com/322-custom-uiviewcontroller-transitions-getting-started

https://github.com/marcosgriselli/EasyTransitions

和我个人最爱:

https://github.com/lkzhao/ElasticTransition

如果您想实现更具体的公共API所没有涵盖的内容,也许您可​​以向我们提供一些代码?

答案 1 :(得分:-2)

我不确定通过使用以下代码,您能否实现所需的功能。但是,我知道如何拨打private-apis。这是拨打相同电话的方法。

let selector = Selector("allowUserInteractionDuringTransition")
self.navigationController?.perform(selector, with: true);

如果上述方法无效,请尝试将选择器名称更改为setAllowUserInteractionDuringTransition

希望,这对您有用。