Xcode创建不使用Storyboard的项目

Xcode创建不使用Storyboard的项目
上周一直在忙蓝牙相关的内容,这周开始进行项目的迁移,下面记录一下使用Xcode创建项目的流程
首先就是在Xcode里面创建一个新项目,这里要设置好项目的名称,使用的语言,以及项目使用的模版,这里先设置为使用Storyboard
之后就得到了一个项目,这个项目还是使用storyboard的项目,可以看到项目的工程文件有一个main.storyboard,如果这个时候启动项目,项目就会加载这个模版中的内容,如果不想使用这个,则可以删除掉这个main.storyboard,然后在项目中进行设置,即删除掉Deployment info中的main interface中的内容
在这里插入图片描述

后面打开项目的info.plist,删除掉下面这个管理项的item0中的key为Storyboard Name的条目
在这里插入图片描述

如果还有的话,删除掉项目info.plist中的Main storyboard file base name条目(一般情况下都没有了)
在这里插入图片描述

之后就可以开始项目的初始化了,打开项目的SceneDelegate.swift文件,可以在scene函数中创建相应的window和Viewcontroller即可完成一个初始化页面的编辑
在这里插入图片描述

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 }
        self.window = UIWindow.init(frame: windowScene.coordinateSpace.bounds)
        self.window?.windowScene = windowScene
        
        self.window?.rootViewController = ViewController()
        self.window?.makeKeyAndVisible()
    }
	
	//...

}

这样的话,就初步完成了项目的初始化,但是很多时候,我们需要设置我们的应用适配低版本的IOS应用,就需要设置项目的的TARGETS的Deployment info里面的IOS版本为10.0,设置Project的Deployment target里面的IOS支持版本为12.1
在这里插入图片描述

在这里插入图片描述

如此操作以后,我们的项目就不能使用UIScene进行项目初始化了,我么也需要修改项目代码,使得项目能够正常启动,首先需要注释了AppDelegate.swift中的两个函数,然后将window的初始化代码迁移到AppDelegate.swift中

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    //如果要适配之前的机型的话,就不能使用SceneDelegate进行页面的创建和初始化了
    //由于Xcode11以后将AppDelegate的生命周期函数和SceneDelegate做了关联,所以先要把下面两个函数注释
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        self.window = UIWindow.init(frame: UIScreen.main.bounds)
        
        self.window?.rootViewController = ViewController()
        self.window?.makeKeyAndVisible()
        return true
    }

    // MARK: UISceneSession Lifecycle

//    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
//        // Called when a new scene session is being created.
//        // Use this method to select a configuration to create the new scene with.
//        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
//    }
//
//    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
//        // Called when the user discards a scene session.
//        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
//        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
//    }


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值