Xcode11-SceneDelegate

方案一: 如果我们不开发iPadOS多窗口APP,SceneDelegate窗口管理我们可以不需要直接删掉就好了。

  1. 删除掉info.plist中Application Scene Manifest选项
  2. 删除项目中的Scenedelegate.h和Scenedelegate.m
  3. 删除掉APPdelegate.m中的#pragma mark - UISceneSession lifecycle代码
  4. 在APPdelegate.h中添加 window属性
@property (strong, nonatomic) UIWindow * window;

方案二:使用iPadOS多窗口,且兼容iOS13以下的

// AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    if (@available(iOS 13, *)) {
        return YES;
    } else {
        [self olderSettingFunc];
        return YES;
    }
    return YES;
    
}
//iOS13以前的设置方法
- (void)olderSettingFunc {
    //设置跟视图控制器
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[MainTabBarController alloc] init];
    [self.window makeKeyAndVisible];
            
}
//SceneDelegate.m
//程序完成启动,和didFinishLaunchingWithOptions相似
- (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).
    
    //设置跟视图控制器
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.windowScene = (UIWindowScene *)scene;//Xcode11以后,设置跟视图,要在SceneDelegate中添加这段代码
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[MainTabBarController alloc] init];
    [self.window makeKeyAndVisible];
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。