如何在自定义容器视图控制器中实现交互式转换 [英] How to implement interactive transitions in a custom container view controller

查看:78
本文介绍了如何在自定义容器视图控制器中实现交互式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了自己的自定义容器视图控制器,并尝试使其与iOS 7视图控制器转换兼容。我使自定义容器视图控制器符合 UIViewControllerContextTransitioning 并在调用 transitionDuration时发送 self animateTransition:。只要我只使用动画过渡,一切都可以正常工作。

I implemented my own custom container view controller and I try to make it compatible with iOS 7 view controller transitions. I make my custom container view controller conform to UIViewControllerContextTransitioning and I send self when I call transitionDuration: and animateTransition:. It all works fine as long as I use only animated transitions.

现在,我想使其与交互式过渡一起使用,因此我将交互控制器称为 startInteractiveTransition:代替动画控制器的 animateTransition:,再次使用 self 作为参数。但是,如果我使用 UIPercentDrivenInteractiveTransition 作为交互控制器,则它将在我的上下文中调用 _animator 方法(即容器视图控制器本身)。当然,我还没有实现这种私有且未记录的方法,所以它崩溃了……

Now I want to make it work with interactive transitions, so I call the interaction controller's startInteractiveTransition: instead of the animation controller's animateTransition:, using self again as a parameter. However, if I use a UIPercentDrivenInteractiveTransition as the interaction controller, it then calls a _animator method on my context (which is the container view controller itself). Of course, I haven't implemented this method which is private and undocumented, so it crashes...

我在实现过程中遗漏了什么吗? UIPercentDrivenInteractiveTransition 仅与Apple类兼容,因为它使用了一些实现魔术(例如,当它要求所有内容都应放在 UIView 动画块)?文档和头文件使我们看起来可以实现我们自己的容器视图控制器,并且仍然使用自定义转换,但这是真的还是只是一厢情愿,因为没人会这样做?

Am I missing something in my implementation? Is UIPercentDrivenInteractiveTransition only compatible with Apple classes because it uses some implementation magic (as when it requires that everything should be in a UIView animation block)? The documentation and header files make it look like we can implement our own container view controllers and still use custom transitions, but is it really true or just wishful thinking because nobody would actually do that?

如果我不能使用 UIPercentDrivenInteractiveTransition ,那么交互/动画逻辑应该在哪里?在 UIViewControllerTransitionCoordinatorContext 对象中?在 UIViewControllerInteractiveTransitioning 对象中(最有可能,该对象是驱动程序...)?或在 UIViewControllerAnimatedTransitioning 对象中(这可能是真正的动画应该发生的位置,但这意味着调用 animateTransition:交互过程中的时间?还是为交互过渡的每个步骤添加新方法?)

If I can't use UIPercentDrivenInteractiveTransition, then where exactly should the interaction/animation logic be? In the UIViewControllerTransitionCoordinatorContext object? In the UIViewControllerInteractiveTransitioning object (most likely, this object is the driver...)? Or in the UIViewControllerAnimatedTransitioning object (this is probably where the real animation should happen, but would that mean calling animateTransition: several times during the interaction? Or adding new methods for each step of the interactive transition?)

编辑:文档显示:


一个百分比驱动的交互式过渡对象在一个视图控制器的消失与另一个视图控制器的出现之间驱动自定义动画。它依赖于过渡动画师委托(即采用 UIViewControllerAnimatorTransitioning 协议的自定义对象)来设置和执行动画。

A percent-driven interactive transition object drives the custom animation between the disappearance of one view controller and the appearance of another. It relies on a transition animator delegate—a custom object that adopts the UIViewControllerAnimatorTransitioning protocol—to set up and perform the animations.

没有 UIViewControllerAnimatorTransitioning 协议。假设这是一个错误,或者是在iOS 7开发过程中发生的名称更改,并且实际上是 UIViewControllerAnimatedTransitioning 协议,我们如何将交互控制器与动画控制器链接?我想这是视图控制器驱动过渡的责任,但我看不到任何API可以建立此链接,因此这意味着 UIPercentDrivenInteractiveTransition 确实为Apple类保留。 ?

There is no UIViewControllerAnimatorTransitioning protocol. Assuming it is a mistake, or a name change that happened during iOS 7 development and it is actually the UIViewControllerAnimatedTransitioning protocol, how do we link the interaction controller with the animation controller? I guess it's the responsibility of the view controller driving the transition but I don't see any API to make this link, so it would mean that UIPercentDrivenInteractiveTransition is indeed reserved for Apple classes?

推荐答案

我试图自己做同样的事情,最终写了自己的 UIPercentDrivenInteractiveTransition 等价物。似乎百分比驱动的过渡要求动画并在交互式过渡开始后实际启动它。我在取消时实施反向动画有些麻烦。

I'm trying to do the same on my own and ended up writing my own UIPercentDrivenInteractiveTransition equivalent. Seems like the percent driven transition asks for the animation and actually starts it after the interactive transition is started. I've got some trouble with implementing the reverse animation when canceling though.

这篇关于如何在自定义容器视图控制器中实现交互式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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