【Swift】iOS设置初始页面

iOS设置初始页面

一些改变

在iOS13以前设置初始页面需要在AppDelegate里实现,但是在iOS13以后设置初始页面需要在SceneDelegate。

设置初始页面(ViewController)

Swift

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        window?.frame = windowScene.coordinateSpace.bounds
        
        let tabBarController = UITabBarController()
        let navigationController = UINavigationController(rootViewController: tabBarController);
        
        window?.rootViewController = navigationController
        window?.makeKeyAndVisible()
    }

OC

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    UIWindowScene *windowScene = (UIWindowScene *)scene;
	self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
	self.window.frame = windowScene.coordinateSpace.bounds;
	UITabBarController *tabBarController= [[UITabBarController alloc] init];
	UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: tabBarController];
	self.window.rootViewController = navigationController;
	[self.window makeKeyAndVisible];
}
    原文作者:百味瓜子
    原文地址: https://blog.csdn.net/weixin_45279502/article/details/121947181
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞