一) 項目中使用SceneDelegate
1)使用Main.StoryBoard
(Default)
無需特殊處理归薛,Xcode 11及其以上版本,默認生成使用'Main.StoryBoard'模板
2)不使用Main.StoryBoard
2.1)在info.plist
文件中找到Storyboard Name
鍵值對,將其移除
2.2)在Base.lproj
文件夾中找到Main.storyboard
病袄,將其移除
2.3)在側(cè)邊欄TARGETS
下框全,選中General
選項卡圾另,找到Deployment Info
項代兵,在Status Bar Style
選項中,勾選Supports multiple windows
選項
2.4)在AppDelegate.h文件中浑彰,新增window屬性
@property (strong, nonatomic) UIWindow *window;
2.5)打開SceneDelegate.m
文件秽梅,在willConnectToSession
代理方法中蓖柔,創(chuàng)建window
窗口,初始化rootViewController
- (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;
self.window.rootViewController = ViewController.new;
[self.window makeKeyAndVisible];
}
二) 項目中不使用SceneDelegate
1)使用Main.StoryBoard
1.1)在info.plist
文件中找到Application Scene Manifest
鍵值對风纠,將其移除
1.2)打開AppDelegate.m
文件况鸣,找到UISceneSession lifecycle
代理方法,將其全部移除竹观,
即configurationForConnectingSceneSession
和didDiscardSceneSessions
兩個方法
#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 [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)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.
}
2)不使用Main.StoryBoard
2.1)在 info.plist
文件中找到 Application Scene Manifest
鍵值對镐捧,將其移除
2.2)在 info.plist
文件中找到 Main storyboard file base name
鍵值對,將其移除
2.3)在Base.lproj
文件夾中找到Main.storyboard
臭增,將其移除
2.4)在AppDelegate.h
文件中懂酱,新增window
屬性
@property (strong, nonatomic) UIWindow *window;
2.5)打開AppDelegate.m
文件,在didFinishLaunchingWithOptions
代理方法中誊抛,創(chuàng)建window
窗口列牺,初始化rootViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(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 = UITabBarController.new;
[self.window makeKeyAndVisible];
return true;
}