Xcode 11创建项目

Xcode 11创建项目

前言

前段时间更新了Xcode 11,创建新项目时,发现工程里面多了新的类`SceneDelegate`,而且原来的`AppDelegate`中没有了Window,原来`SceneDelegate`是iOS 13中新加入的管理App生命周期的类,而且通过Storyboard加载页面,下面我就如何不使用Storuboard,来完成App启动。

8FCE99D8-FAB2-4419-BFEA-0367135336B4

OC

1.首先,肯定是在工程中找到Main.storyboard这个文件,然后删掉他。

屏幕快照 2019-09-27 上午9.41.13

2.在工程中Targets->项目名->General->Main Interface->删掉Main

屏幕快照 2019-09-27 上午9.45.56

3.工程中info.plist 找到ApplicationSceneManifest->Scene Configurations->ApplicationSessionRole->删掉StoryboardName

在SceneDelegate.m

1
2
3
4
5
6
7
8
9
10
11
12
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.windowScene = scene;
ViewController *new = [ViewController new];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:new];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];

// 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).
}

这样就可以了

Swfit

1、2、3步一样,在SceneDelegate.swift

1
2
3
4
5
6
7
8
9
10
11
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 windowScene = (scene as? UIWindowScene) else { return }

window = UIWindow.init(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
}
-------------本文结束感谢您的阅读-------------