Xcode11: 删除默认Main.storyBoard, 自定义UIWindow的变化 UIWindow 不能在AppDelegate中处理

原文地址:https://blog.csdn.net/Rzhghost/article/details/101675332

Xcode自动新增了一个SceneDelegate文件,查找了一下官方文档WWDC2019:Optimizing App Launch 发现,iOS13中appdelegate的职责发现了改变: iOS13之前,Appdelegate的职责全权处理App生命周期和UI生命周期; iOS13之后,Appdelegate的职责是: 1、处理 App 生命周期 2、新的 Scene Session 生命周期 那UI的生命周期呢?交给新增的Scene Delegate处理, Appdelegate不在负责UI生命周期,所有UI生命周期交给SceneDelegate处理

除了与以前版本一样,要删除Main storyboard file base name之外, 还要在项目Info.plist中, 删除SceneDelegate的StoryboardName

初始化window方法需要改变: 现在不再在Appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions进行初始化, 而是在SceneDelegate中初始化了

- (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.backgroundColor = [UIColor purpleColor];

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

    UINavigationController *NVC = [[UINavigationController alloc]initWithRootViewController:VC];

    [self.window setRootViewController:NVC];

    [self.window makeKeyAndVisible];

}

————————————————

版权声明:本文为CSDN博主「Rzhghost」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/Rzhghost/article/details/101675332

你可能感兴趣的:(Xcode11: 删除默认Main.storyBoard, 自定义UIWindow的变化 UIWindow 不能在AppDelegate中处理)