(Objective-C) SceneDelegate use and removal precautions and split screen

1) Use SceneDelegate in the project

1) Use Main.StoryBoard(Default)

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

2) do not useMain.StoryBoard

2.1) info.plistFind Storyboard Namethe key-value pair in the file and remove it

Storyboard Name

2.2) Base.lprojFound in the folder Main.storyboard, remove it

Main

2.3) Under the sidebar TARGETS, select Generalthe tab, find Deployment Infothe item, in Status Bar Stylethe option, check Supports multiple windowsthe option

Status Bar Style

2.4) Find the AppDelegate.h file and add the window attribute

@property (strong, nonatomic) UIWindow *window;

2.5) Open SceneDelegate.mthe file, in willConnectToSessionthe proxy method, create windowa window, initializerootViewController

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

2) SceneDelegate is not used in the project

1) useMain.StoryBoard

1.1) info.plistFind Application Scene Manifestthe key-value pair in the file and remove it

Application Scene Manifest

1.2) Open AppDelegate.mthe file, find UISceneSession lifecyclethe proxy method, and remove them all,
that is , configurationForConnectingSceneSession and didDiscardSceneSessionsthe two methods

#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) do not useMain.StoryBoard

2.1)  info.plist Find  Application Scene Manifest the key-value pair in the file and remove it

Application Scene Manifest

2.2)  info.plist Find  Main storyboard file base name the key-value pair in the file and remove it

Main storyboard file base name

2.3) Base.lprojFound in the folder Main.storyboard, remove it

Main

2.4) Find AppDelegate.hthe file and add windowattributes

@property (strong, nonatomic) UIWindow *window;

2.5) Open AppDelegate.mthe file, in didFinishLaunchingWithOptionsthe proxy method, create windowa window, initializerootViewController

- (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;
}

3) Added SceneDelegate and detailed explanation of split screen

1. The main change--split screen

Open an APP first, slide out the dock bar from the bottom up, then drag the app icon you want to divide into columns in the dock bar, and put it on the right or left.
Fifty-five points or thirty-seven points, press and hold the middle line, and drag left and right.

2. On which devices can split screen be implemented?

iPhone does not support split screen at this time. .

3. Project development needs attention

1. Split screen is required.
If your project is also compatible with versions below iOS13, you can delete the configuration data info.plistin Application Scene Manifest. Then windowput the attribute in the same way as before AppDelegate, and the deleted UISceneSessionstatement cycle method is OK.
2. No split screen required.
If you do not delete Application Scene Manifestthis configuration, you need to make two sets of configurations to adapt to iOS 13 and below versions.
iOS 13 is mainly in  SceneDelegatethe middle;
iOS 13 and later versions are mainly in AppDelegatethe middle
3. When you need to split the screen, you need to do the following two configurations
(1) In General, checkSupports multiple windows

(2) In info.plist, Application Scene Manifest -> Enable Multiple Windowsset it to YES

Guess you like

Origin blog.csdn.net/u011569892/article/details/128934936