SceneDelegate

iOS13 Scene Delegate詳解~http://www.itdecent.cn/p/53e3252dc07e?

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

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

iOS13中appdelegate的職責發(fā)現(xiàn)了改變:

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

}

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容