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];
});