分类
iOS学习

Xcode 11新建swift 项目

如题 新建swift项目

1、在AppDelegate中声明window属性

2、AppDelegate中两个关于Scene的类添加版本控制,用扩展单独拎出来

@UIApplicationMain
 
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
 
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        if #available(iOS 13, *) {
        }else {
            window = UIWindow.init()
            window?.frame = UIScreen.main.bounds
            window?.makeKeyAndVisible()
            window?.rootViewController = UIViewController.init()
        }
        return true
        
    }
}
 
@available(iOS 13.0, *)
extension AppDelegate {
    // MARK: UISceneSession Lifecycle
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
 
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    }
}

3、SceneDelegate中添加版本控制

import UIKit
@available(iOS 13, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
 
    var window: UIWindow?
 
 
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        
        let windowScene:UIWindowScene = scene as! UIWindowScene
        window = UIWindow.init(windowScene: windowScene)
        window?.backgroundColor = UIColor.green
        window?.frame = UIScreen.main.bounds
        window?.makeKeyAndVisible()
        let tt = UIViewController.init()
        tt.view.backgroundColor = UIColor.brown
        window?.rootViewController = tt
        guard let _ = (scene as? UIWindowScene) else { return }
    }
}

“Xcode 11新建swift 项目”上的3条回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注