iOS设置初始页面
一些改变
在iOS13以前设置初始页面需要在AppDelegate里实现,但是在iOS13以后设置初始页面需要在SceneDelegate。
设置初始页面(ViewController)
Swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window?.frame = windowScene.coordinateSpace.bounds
let tabBarController = UITabBarController()
let navigationController = UINavigationController(rootViewController: tabBarController);
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
OC
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
UITabBarController *tabBarController= [[UITabBarController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: tabBarController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
}