iOS常用

适配SceneDelegate

2020-07-28  本文已影响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;
}

上一篇下一篇

猜你喜欢

热点阅读