一、Main.StoryBoard的使用

1、使用Main.StoryBoard(Default)

无需特殊处理,Xcode 11及其以上版本,默认生成用’Main.StoryBoard’模板

2、不使用Main.StoryBoard

  • a、在info.plist文件中找到Storyboard Name键值对,将其移除
    在这里插入图片描述
  • b、在TARGETS->info下找到Main storyboard file base name键值对,将其移除
    在这里插入图片描述
  • c、删除Main.storyboard
  • d、在侧边栏TARGETS->General下,找到Deployment Info项,在Status Bar Style选项中,勾选Supports multiple windows选项

二、SceneDelegate的使用

1、项目中使用SceneDelegate

  • a、打开SceneDelegate.m文件,在scenewillConnectToSession代理方法中,创建window窗口,初始化rootViewController
    -(void)scene:(UIScene*)scenewillConnectToSession:(UISceneSession*)sessionoptions:(UISceneConnectionOptions*)connectionOptions {
    UIWindowScenewindowScene = (UIWindowScene)scene;
    self.window= [[UIWindowalloc]initWithWindowScene:windowScene];
    self.window.frame = windowScene.coordinateSpace.bounds;
    self.window.rootViewController = ViewController.new;
    [self.window makeKeyAndVisible];
    }

2、 项目中不使用SceneDelegate

  • a、在info.plist文件中找到Application Scene Manifest键值对,将其移除
    在这里插入图片描述
  • b、在AppDelegate.m文件,移除UISceneSession lifecycle代理方法, 即application configurationForConnectingSceneSession 和applicationdidDiscardSceneSessions两个方法
    #pragma mark - UISceneSession lifecycle
    -(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions )options {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return[[UISceneConfigurationalloc]initWithName:@"Default Configuration"sessionRole:connectingSceneSession.role];
    }
    -(void)application:(UIApplication
    )applicationdidDiscardSceneSessions:(NSSet *)sceneSessions {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
  • c、AppDelegate.h文件,新增window属性
    @property (strong, nonatomic) UIWindow *window;
  • d、AppDelegate.m文件中,在applicationdidFinishLaunchingWithOptions代理方法中,创建window窗口,初始化rootViewController
    -(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = UIColor.whiteColor;
    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];
    [self.window makeKeyAndVisible];
    return YES;
    }
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐