欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Xcode11前后自定义窗口

程序员文章站 2022-03-03 19:22:43
Xcode11前- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Xcode11前生效 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [U...

Xcode11前

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //Xcode11前生效
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    UIViewController *vC = [[CustomViewController alloc] init];
    self.window.rootViewController = vC;
    //window核心化可见
    [self.window makeKeyAndVisible];
    return YES;
}

Xcode11后

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions  API_AVAILABLE(ios(13.0)) API_AVAILABLE(ios(13.0)) API_AVAILABLE(ios(13.0)){
    //Xcode11后生效
    //scene行参字段名表象特征结构为UIScene*但持有的实例值的实际特征结构为UIWindowScene*
    //强制类型转化
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
    } else {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    }
    self.window.backgroundColor = [UIColor whiteColor];
    UIViewController *vC = [[CustomViewController alloc] init];
    self.window.rootViewController = vC;
    //window核心化可见
    [self.window makeKeyAndVisible];
}

本文地址:https://blog.csdn.net/yanhaijunyan/article/details/111938211