我正在阅读 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/