用于在iOS中实现完全自定义containerViewController的类体系结构 [英] Class architecture for implementing a fully custom containerViewController in iOS

查看:273
本文介绍了用于在iOS中实现完全自定义containerViewController的类体系结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建自己的Custom ContainerViewController。

I'm currently trying to build my own Custom ContainerViewController.

我非常熟悉iOS ViewController包含API(在iOS 5中引入)和新版本iOS7 ViewController Transition API。

I'm quite familiar with the iOS ViewController containment API (introduced in iOS 5) and the new iOS7 ViewController Transition API.

在实现我的容器时,我尝试使用UINavigationController和UITabBarController使用的相同模式。

While implementing my container, i tried to utilize the same patterns UINavigationController and UITabBarController are using.

我的容器到目前为止运行良好并正确使用动画和交互式过渡。

My Container is working well so far and using animated and interactive transitions properly.

问题是,我将大量逻辑打包到我的UIViewController容器子类中。它符合< UIViewControllerContextTransitioning> 并使用iVars存储该协议方法返回的所有值。

The Problem is, i packed a huge amount of the logic into my UIViewController container subclass. It is conforming to <UIViewControllerContextTransitioning> and uses iVars to store all the values returned by that protocol's methods.

动画和交互逻辑已经在另一个类中分离,第三方也可以使用类似 UINavigationControllerDelegate UITabBarControllerDelegate的委托来提供自己的转换。

The animation and interaction logic is already separated in another class and third-parties are also able to provide their own transition using a delegate similar to UINavigationControllerDelegate and UITabBarControllerDelegate.

我现在要做的是外包 UIViewControllerContextTransitioning 到一个单独的类来创建Apple为它的containerVCs所做的相同的模块化。
Apple为 id< UIViewControllerContextition> 对象提供 UIViewControllerOneToOneTransitionContext (私有API) c $ c> UIViewControllerAnimatedTransitioning 和 UIViewControllerInteractiveTransitioning 方法。所以他们没有使用他们的UIViewController子类。 (这就是我现在所做的事情)

What I'm trying to do now is out-sourcing the UIViewControllerContextTransitioning to a separate class to create the same modularity Apple does for it's containerVCs. Apple provides a UIViewControllerOneToOneTransitionContext (private API) for the id<UIViewControllerContextTransitioning> object handed to the UIViewControllerAnimatedTransitioning and UIViewControllerInteractiveTransitioning methods. So they are NOT using their UIViewController subclass for that. (That's what i do at the moment)

到目前为止,当转换逻辑调用 [updateInteractiveTransition时]我的当前结构很有意义。 :] [completeTransition:] 等,在上下文中,这些调用直接在我的containerController上进行,然后可以通过更新其他元素来响应在它看来。 (就像UINavigationController一样,当你调用 [updateInteractiveTransition:] 并且它正在更新NavigationBar的内容(交叉淡入淡出))。

My current structure is in so far tempting to keep for me as when the transition logic calls [updateInteractiveTransition:], [completeTransition:], etc. on the context, these calls are made directly on my containerController which can then respond by updating other elements in it's view. (Like UINavigationController does when you call [updateInteractiveTransition:] and it's updating the content of the NavigationBar (cross-fade)).

在另一个类中外包上下文转换逻辑意味着:

Out-Sourcing the contexttransitioning logic in another class would mean:


  • 提供viewControllers和框架等等我的容器的堆栈从容器到上下文对象,因为上下文需要将它们提供给转换逻辑。

  • 调用transition-callbacks FROM上下文对象在容器上因为上下文对象是从过渡逻辑中接收它们的那个。

由于Apple使用这种类关系,它必须有一些优势,我猜测。
目前,我不知道我是否应该保留我的实现,或者尝试将其设置为模块化的Apple提供的容器。

As Apple uses this class-relationship, there must be some advantage about it, i guess. Currently, i don't know if i should keep my implementation, or try to make it as modular as Apple-provided containers.

另见< a href =https://stackoverflow.com/questions/21306496/how-to-cancel-view-appearance-transitions-for-custom-container-controller-tran/21797579?noredirect=1> SO - 问题我问同样的事情。 (更像是一个回答问题,抱歉:/)

Also see this SO - Question where i asked the same thing. (More like an answer-question, sorry for that :/ )

我们讨论的主题是:是否可以使我的容器与UIPercentDrivenInteractiveTransition一起工作?文档说它会切断关键帧中transitionAnimator执行的动画,并逐步自动重放动画过渡,所以我怀疑它可以用于自定义容器。

While we're on the topic : Is it possible to make my container work with UIPercentDrivenInteractiveTransition ? The documentation says it cuts the animation executed by the transitionAnimator in keyframes and automagically "replays" the animated transition step by step, so i doubt it can be used with custom containers.

感谢您的帮助!

推荐答案

Apple使用许多符合某些协议的小类来交付工作。分而治之。例如,看看UITableView的操作方式或集合视图。他们确实将事物分成了最小的块,并为每个块提供了一些通用对象。这些对象仅符合某些协议。

Apple uses a lot of small classes conforming to certain protocols to hand over pieces of work. Divide and conquer. Have a look at for instance the way UITableView operates or collection view. They did split things into smallest chunks possible, and provided each one with some generic objects. These objects only conform to certain Protocols.


  • 不要强迫人们继承。

  • 创建履行某些角色的类必须符合的协议。

  • 您希望创建准备使用的对象以执行某些操作 - 返回id类型的对象,而不是类对象。这是保持简单和灵活的唯一方法。
    Apple即使使用NSObject也可以做到这一点,NSObject既是类又是协议。
    创建自己的协议时,请记住使它们符合NSObject *协议。

您的问题相当长,并没有提出任何具体问题,所以我希望这可以解答您的一些疑虑。如果没有,请随意发一个回复。

Your question is rather long, and does not ask any specific questions, so I hope this answers some of your concerns. If not, feel free to post one to response to this.

这篇关于用于在iOS中实现完全自定义containerViewController的类体系结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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