ios - 正确中继自定义容器 View Controller 中的外观方法调用

标签 ios ios5 uiviewcontroller

我正在关注 Apple's guide构建我自己的自定义容器 View Controller 。它似乎开箱即用,除了一个恼人的问题。

我如何准确指定我的 subview Controller 将接收 viewWillAppear:viewDidAppear: 调用(及其对应的 disappear) ?

假设我有一个 child 滑入 parent 或类似东西的奇特动画。很自然地,我希望在动画开始时调用 viewWillAppear:YES,在结束时调用 viewDidAppear:YES。但是,默认情况下,当我的 child 的 View 被添加到父 View 时,viewWillAppear:NOviewDidAppear:NO 会同时被调用。

现在,我知道在 iOS 6 中添加了 beginAppearanceTransition:animated:endAppearanceTransition 方法,但我想支持 iOS 5。它看起来也像它们旨在用于高级案例:

Once you add a child to a container, the container automatically forwards rotation and appearance callbacks to the child view controllers as soon as an event occurs that requires the message to be forwarded. This is normally the behavior you want, because it ensures that all events are properly sent. However, sometimes the default behavior may send those events in an order that doesn’t make sense for your container. For example, if multiple children are simultaneously changing their view state, you may want to consolidate the changes so that the appearance callbacks all happen at the same time in a more logical order. To do this, you modify your container class to take over responsibility for appearance or rotation callbacks.

还有 transitionFromViewController:toViewController:duration:options:animations:completion: 方法在适当的时候调用外观方法,但它需要两个 View Controller 在运行,通常在这里看起来不合适。当然,我可能会耍花招,给它喂一个假 child ,但说真的……

有什么我想念的吗?任何帮助将不胜感激。

最佳答案

答案有点有趣。

文档可能会说 beginAppearanceTransition:animated:endAppearanceTransition 在 iOS 6+ 中可用,但事实并非如此。这些方法也适用于 iOS 5:

- (void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
- (void)endAppearanceTransition __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

This question's answer也陈述了同样的事情。破案了!

关于ios - 正确中继自定义容器 View Controller 中的外观方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16651579/

相关文章:

ios - 如何交错实数和复数数组以使用 vDSP_ctoz?

ios - downloadTaskWithRequest 混淆行为(swift,IOS)

iphone - NSURLConnection 挂了

ios - 在 View Controller 之间传递数据

ios - 使用 Cocoapods 安装 AFNetworking 后 undefined symbol

ios - 类在目标中被多次链接

ios - MapKit 中的 MapTypeStyle

iphone - iOS5中的phonegap后台服务

asynchronous - 从异步函数重新加载 UITable 调用

ios - 无法识别的选择器发送到实例 - UIViewController