简体   繁体   English

带有dismissViewControllerAnimated的iOS 8错误:完成:动画?

[英]iOS 8 bug with dismissViewControllerAnimated: completion: animation?

iOS documentation for dismissViewControllerAnimated:completion: states: dismissViewControllerAnimated:completion: iOS文档dismissViewControllerAnimated:completion:状态:

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. 如果连续呈现多个视图控制器,从而构建一堆呈现的视图控制器,则在堆栈中较低的视图控制器上调用此方法会解除其直接子视图控制器以及堆栈上该子视图上方的所有视图控制器。 When this happens, only the top-most view is dismissed in an animated fashion; 发生这种情况时,只有最顶层的视图以动画方式被删除; any intermediate view controllers are simply removed from the stack. 任何中间视图控制器都可以从堆栈中删除。 The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack. 最顶层的视图使用其模态过渡样式被忽略,这可能与堆栈中较低的其他视图控制器使用的样式不同。

This means when dismissing two modal view controllers at once using 这意味着在使用时立即解除两个模态视图控制器

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

the animation shown should be the top modal view being dismissed. 显示的动画应该是被解雇的顶级模态视图。

This is indeed the case in iOS 7 and prior, but in iOS 8 the animation shown is not the top-most view (in my experience, it's the second top-most view). 在iOS 7和之前的情况确实如此,但在iOS 8中,所显示的动画并不是最顶级的视图(根据我的经验,它是第二个最顶层的视图)。 Is this behavior a bug in iOS 8 or am I doing something wrong? 这种行为是iOS 8中的错误还是我做错了什么?

As commented above: I see the exact same issue in an unwind segue context. 如上所述:我在展开的segue上下文中看到完全相同的问题。 I just toke the workaround as described here using a screenshot and add it as a subview to all intermediate viewControllers: 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? 我只是使用屏幕截图来解决此处所述的解决方法,并将其作为子视图添加到所有中间viewControllers: 如何使用动画解除一堆模态视图控制器而不在屏幕上闪烁顶部和底部之间的任何呈现的VC?

    // 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;
    }

Same problem and same solution here than @theguy. 与@theguy相同的问题和相同的解决方案。 Here's my version in Swift without iterating on all the view controllers : 这是我在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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM