SceneDelegate

iOS13 Scene Delegate详解~//www.greatytc.com/p/53e3252dc07e 

上面有兼容iOS12及一下的方法

下面是直接在新项目里做iOS13及以上版本的方法

iOS13中appdelegate的职责发现了改变:

iOS13之前,Appdelegate的职责全权处理App生命周期和UI生命周期;

iOS13之后,Appdelegate的职责是:

1、处理 App 生命周期

2、新的 Scene Session 生命周期

那UI的生命周期交给新增的Scene Delegate处理

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {

    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.

    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.

    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

    UIWindowScene *windowScene = (UIWindowScene *)scene;

    self.window = [[UIWindow alloc] initWithWindowScene:windowScene];

    self.window.frame = windowScene.coordinateSpace.bounds;


    UITabBarController *tabbarController = [[UITabBarController alloc] init];


    UIViewController *controller1 = [[UIViewController alloc] init];

    controller1.view.backgroundColor = [UIColor redColor];

    controller1.tabBarItem.title = @"新闻";


    UIViewController *controller2 = [[UIViewController alloc] init];

    controller2.view.backgroundColor = [UIColor yellowColor];

    controller2.tabBarItem.title = @"视频";


    UIViewController *controller3 = [[UIViewController alloc] init];

    controller3.view.backgroundColor = [UIColor blueColor];

    controller3.tabBarItem.title = @"推荐";


    UIViewController *controller4 = [[UIViewController alloc] init];

    controller4.view.backgroundColor = [UIColor greenColor];

    controller4.tabBarItem.title = @"我的";


    // 将四个页面的 UIViewController 加入到 UITabBarController 之中

    [tabbarController setViewControllers: @[controller1, controller2, controller3, controller4]];


    self.window.rootViewController = tabbarController;

    [self.window makeKeyAndVisible];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容