xcode: Version 11.3.1 (11C504)
iOS: 13
语言:Swift/Objective-C
指定根视图,兼容iOS13以及iOS13之前的系统:
SceneDelegate.swift
文件中修改
@available(iOS 13.0, *)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// 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).
guard let winScene = (scene as? UIWindowScene) else { return }
// Create the root view controller as needed
let vc = LoginViewController()
let nc = UINavigationController(rootViewController: vc)
// Create the window. Be sure to use this initializer and not the frame one.
let win = UIWindow(windowScene: winScene)
win.rootViewController = nc
win.makeKeyAndVisible()
window = win
}
AppDelegate.swift
文件中修改
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
let loginVC = LoginViewController()
let navi = UINavigationController(rootViewController: loginVC)
window?.rootViewController = navi
window?.makeKeyAndVisible()
return true
}
2021年2月5号更新:
更新内容Objective-C版本。
Appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CGRect mainRect = [UIScreen mainScreen].bounds;
self.window = [[UIWindow alloc]initWithFrame:mainRect];
MainViewController *mainVC = [[MainViewController alloc]init];
UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:mainVC];
self.window.rootViewController = naviVC;
[self.window makeKeyAndVisible];
return YES;
}
SceneDelegate
- (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 alloc]initWithSession:session connectionOptions:connectionOptions];
self.window = [[UIWindow alloc]initWithWindowScene:windowScene];
MainViewController *mainVC = [[MainViewController alloc]init];
UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:mainVC];
self.window.rootViewController = naviVC;
[self.window makeKeyAndVisible];
}
完美结束