iOS15 上 rootViewController 替换 vc

2022-08-03  本文已影响0人  SwiftBest

iOS15 替换 rootViewController 失败, 在 iOS15 之前没有发现该问题。

  [UIApplication sharedApplication].keyWindow.rootViewController = vc;

最后我发现延迟 0.1 秒后可以正常显示。

   double delayInSeconds = 0.1;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        TabBarViewController *tabbar = [[TabBarViewController alloc] init];
        UIWindow *nWindow;
        if (@available(iOS 13.0, *)) {
            nWindow = [UIApplication sharedApplication].windows[0];
        } else {
            nWindow = [UIApplication sharedApplication].delegate.window;
        }
        [nWindow setRootViewController:tabbar];
    });
上一篇下一篇

猜你喜欢

热点阅读