1.建立項目
2.解決ios13以下運作閃退問題
1)删除SceneDelegate.swift
官方文檔:
In iOS 13 and later, use UISceneDelegate objects to respond to life-cycle events in a scene-
based app.
這個場景呢,如果不使用ipad的多視窗就不建議使用
2)删除 Main.storyboard,不使用storyboard布局,打開info.plist,删除Main storyboard file base name和Application Scene Manifest選項。
3)删除appdelegate 中關于scene的2個代理
4)appdelegate中添加根導航
//swift
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let screen = UIScreen.main.bounds //獲得裝置尺寸
self.window = UIWindow.init(frame: screen) //給“輸出視窗“執行個體化并設定frame
let viewController = ViewController() //執行個體化一個ViewController
let navigationController = UINavigationController(rootViewController: viewController) //為ViewController設定一個導航欄
self.window?.rootViewController = navigationController//将“輸出視窗”的根視圖設定為導航欄
self.window?.makeKeyAndVisible() // 設定"輸出視窗可見"
return true
}
}
//OC
@interface AppDelegate ()<UISplitViewControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]init];
self.window.frame = [UIScreen mainScreen].bounds;
LogInViewController *loginVC = [[LogInViewController alloc]initWithNibName:@"LogInViewController" bundle:nil];
self.window.rootViewController = loginVC;
[self.window makeKeyAndVisible];
return YES;
}
參考自:https://www.xugj520.cn/archives/xcode-swift.html