美文网首页iOS常用
适配SceneDelegate

适配SceneDelegate

作者: 冰点雨 | 来源:发表于2020-07-28 15:02 被阅读0次

    方法一:

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    /// 兼容iOS13之前的版本
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        
        if (@available(iOS 13.0, *))
          {
              // 在SceneDelegate里创建UIWindow
          }
          else
          {
              self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
              [self.window setBackgroundColor:[UIColor whiteColor]];
    
              NSString *mainStoryboardFileName    =
              [[NSBundle mainBundle].infoDictionary valueForKey:@"UIMainStoryboardFile"];
    
              UIStoryboard *mainStoryboard        =
              [UIStoryboard storyboardWithName:mainStoryboardFileName
                                        bundle:[NSBundle mainBundle]];
    
              [self.window setRootViewController:[mainStoryboard instantiateInitialViewController]];
              [self.window makeKeyAndVisible];
          }
    
        
        return YES;
    }
    

    方法二:
    apppdegate中添加:@synthesize window = _window;

    @implementation AppDelegate
    
    @synthesize window = _window;
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        
        return YES;
    }
    
    

    相关文章

      网友评论

        本文标题:适配SceneDelegate

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