美文网首页
Xcode11-SceneDelegate

Xcode11-SceneDelegate

作者: 扣肉快快跑 | 来源:发表于2020-11-06 12:14 被阅读0次

    方案一: 如果我们不开发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];
    }
    

    相关文章

      网友评论

          本文标题:Xcode11-SceneDelegate

          本文链接:https://www.haomeiwen.com/subject/skfavktx.html