首页 > 解决方案 > iOS13中具有多个窗口场景的最顶级视图控制器

问题描述

我正在使我的应用程序在带有iOS 13的iPadOS上使用多个窗口,据我所知,由于它已被弃用,我无法直接访问窗口,我怎样才能获得最顶层的视图控制器?UIApplication

iOS12之前我使用这个工作解决方案,你能建议一个替代方案吗?

+(UIViewController *)topMostViewController
{
    UIViewController *vc = [[UIApplication sharedApplication].delegate.window rootViewController];
    while(vc.presentedViewController)
    {
        vc = vc.presentedViewController;
    }
    return vc;
}

标签: uiwindowuiapplicationios13uiscene

解决方案


请参阅:如何获取多窗口 SceneDelegate Xcode 11 的当前 keywindow 等效项?

已弃用: 您尝试过Application.shared.keyWindow?.rootViewController吗?keyWindow (或者如果你喜欢)是这里的重要部分mainWindow


推荐阅读