Xcode11 之前:
window 在 AppDelegate 中設(shè)置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [SSHomeVC new];
[self.window makeKeyAndVisible];
return YES;
}
使用 Xcode11 創(chuàng)建的項(xiàng)目中:
除了自動(dòng)創(chuàng)建AppDelegate 文件外,還創(chuàng)建了SceneDelegate文件,這適用于 iOS13 之后.此時(shí) AppDelegate 文件中已經(jīng)沒有 UIWindow 對(duì)象,而在 SceneDelegate中:
#import <UIKit/UIKit.h>
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
此時(shí)自定義UIWindow,設(shè)置控制器需要:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.rootViewController = [SSHomeVC new];
[self.window makeKeyAndVisible];
}