【问题标题】:iOS 8 bug with dismissViewControllerAnimated: completion: animation?带有dismissViewControllerAnimated的iOS 8错误:完成:动画?
【发布时间】:2015-02-17 15:41:03
【问题描述】:

dismissViewControllerAnimated:completion: 的 iOS 文档状态:

如果你连续呈现几个视图控制器,从而构建一个 呈现的视图控制器堆栈,在视图上调用此方法 堆栈中较低的控制器关闭其直接子视图 控制器和堆栈上该子级上方的所有视图控制器。 发生这种情况时,只有最顶层的视图会在动画中消失 时尚;任何中间视图控制器都被简单地从 堆。最顶层的视图使用其模态转换被关闭 样式,可能与其他视图控制器使用的样式不同 在堆栈中较低。

这意味着当使用一次关闭两个模态视图控制器时

[[[self presentingViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];

显示的动画应该是被关闭的顶部模态视图。

在 iOS 7 及之前的版本中确实如此,但在 iOS 8 中显示的动画不是最顶层的视图(根据我的经验,它是第二个最顶层的视图)。这种行为是 iOS 8 中的错误还是我做错了什么?

【问题讨论】:

  • 你的意思是最顶部的视图在动画开始时突然消失了吗?
  • 我很确定这是一个错误。如果您执行返回多个控制器的展开转场,也会发生这种情况(如果我没记错的话,在这种情况下,您确实会看到顶视图消失,但也会短暂地看到倒数第二个控制器)。
  • 是否向 Apple 提交了错误报告?我不知道该怎么做或如何检查。
  • 我在 unwind segue 上下文中看到了完全相同的问题。帮助会很棒。

标签: ios uiviewcontroller ios8 modalviewcontroller


【解决方案1】:

如上所述:我在展开的 segue 上下文中看到了完全相同的问题。我只是使用屏幕截图按照此处所述的解决方法,并将其作为子视图添加到所有中间视图控制器:How to dismiss a stack of modal view controllers with animation without flashing on screen any of the presented VCs between the top and bottom?

    // this in during unwind in a custom UIStoryboardSegue (that is the reason why it might look wrong with what is what: srcViewController and destViewController
    UIViewController* aPresentedViewController = destViewController.presentedViewController;
    while (aPresentedViewController != nil) {
        if (aPresentedViewController == srcViewController) {
            break;
        }
        UIView *anotherSrcViewCopy = [srcViewController.view snapshotViewAfterScreenUpdates: NO];
        anotherSrcViewCopy.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        [aPresentedViewController.view addSubview:anotherSrcViewCopy];
        // recurse through the presentedViewController hierarchy
        aPresentedViewController = aPresentedViewController.presentedViewController;
    }

【讨论】:

    【解决方案2】:

    与@theguy 相同的问题和相同的解决方案。 这是我在 Swift 中的版本,没有在所有视图控制器上进行迭代:

    guard
        let presentedViewController = segue.destination.presentedViewController,
        let viewToCopy              = segue.source.view.snapshotView(afterScreenUpdates: false)
    else { return }
    
    viewToCopy.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    presentedViewController.view.addSubview(viewToCopy)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 2014-11-12
      • 2012-06-20
      • 1970-01-01
      相关资源
      最近更新 更多