ios - 为什么我们需要在成功解雇转换后从容器 View 中删除 toView?

标签 ios objective-c view uiviewcontroller transition

我正在阅读 View Controller Programming Guide for iOS这些天,它说:

Because transitions can be canceled, you should use the return value of the transitionWasCancelled method of the context object to determine what cleanup is required. When a presentation is canceled, your animator must undo any modifications it made to the view hierarchy. A successful dismissal requires similar actions.

在 Presentations and Transitions->Customizing the Transition Animations->Implementing Your Animator Objects->Cleaning Up After the Animations.

以及Apple提供的示例代码:

BOOL success = ![transitionContext transitionWasCancelled];

// After a failed presentation or successful dismissal, remove the view.
if ((self.presenting && !success) || (!self.presenting && success)) {
     [toView removeFromSuperview];
}

// Notify UIKit that the transition has finished
[transitionContext completeTransition:success];

我知道dismissal首先要给容器view添加toView,为什么dismissal成功后还要remove toView呢? 我已经测试过,如果我在成功解雇后不调用 removeFromSuperview,一切正常。

如果解雇失败会怎样?它仍然会显示呈现的 View Controller 还是关闭它并显示呈现的 View Controller ?

有人知道吗?非常感谢。

最佳答案

通常,当您在交互中使用自定义动画时,就会发生这种情况。但是,如果万一动画被取消并且您不处理取消状态,那么它将保持呈现的 View Controller 状态。(在您的情况下)

关于ios - 为什么我们需要在成功解雇转换后从容器 View 中删除 toView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36369206/

相关文章:

view - Ember.js View 参数将 html 显示为纯文本

ios - 我想在我的 iOS 应用程序中实现以下下拉功能。怎样才能做到?

javascript - 如何在 iOS 应用程序中更改 iPhone 位置时旋转照片

ios - HomeKit 崩溃原因 : '-[__NSDate length]: but Bool sent

ios - 具有动态高度的 subview 的自动布局 UIScrollView

android - 如何为 Android Imagebutton 设置 20% alpha 值?

从 GDB 中查看/打印功能代码

ios - 在 .swift 文件中,为什么有些函数不在类括号内

iphone - 如何在 iPhone 中解析 gdata xml?

ios - 什么时候在 block 中引用 self 是一个保留周期?