UIApplicationDelegate
为了支持scene,在UIApplicationDelegate
方法中增加了,下面方法
核心实现方法
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)){
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0)){
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
- configurationForConnectingSceneSession
需要通过这个方法去info.plist中读取scene信息,创建新的scene
scene代理
一个实现UIWindowSceneDelegate
的类,继承自
UIResponder
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
@property (strong, nonatomic) UIWindow * window;
@end
对于Application Session Role的scene,需要创建root window。如果已经在Info.plist中的Scene Configuration指定了Storyboard Name,那么root window会自动从Storyboard中创建。如果没有指定Storyboard Name,那么就需要在-[UIWindowSceneDelegate scene:willConnectToSession:options:]中手动创建root window。
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
// 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).
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
[self.window setWindowScene:windowScene];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self setsViewController];
// [self.window setRootViewController:[UITabBarController new]];
[self.window makeKeyAndVisible];
}
网友评论