加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

The Swift Code之应用程序的启动过程

发布时间:2020-12-14 02:15:25 所属栏目:百科 来源:网络整理
导读:The Swift Code主要是通过编写代码来完成应用程序的实现,使我们更能够深入的了解其编程语言实现的原理.也能够辅助更快的使用XCODE开发应用程序. 这篇文章主要是讲解启动应用程序从代码入口. 其实这里主要是通过注解来实现的,新建IOS swift项目的时候,会生成

The Swift Code主要是通过编写代码来完成应用程序的实现,使我们更能够深入的了解其编程语言实现的原理.也能够辅助更快的使用XCODE开发应用程序.

这篇文章主要是讲解启动应用程序从代码入口.

其实这里主要是通过注解来实现的,新建IOS swift项目的时候,会生成一个AppDelegate文件,这个文件就是应用程序的代码入口,在声明类的同时加入了注解@UIApplicationMain,表明这个应用程序.其实在这之前,我们必须在配置文件里设置启动入口为Main

4801DAAE-B3CF-4446-B37D-97761FC4D9BC.png

以下讲解,我们在代码里做讲解,大家可以试试在模拟里调试

importUIKit

@UIApplicationMain
classAppDelegate:UIResponder,UIApplicationDelegate{

varwindow:UIWindow?

/*程序未启动时,点击应用程序触发该方法,之后触发applicationDidBecomeActive*/
funcapplication(application:UIApplication,didFinishLaunchingWithOptionslaunchOptions:[NSObject:AnyObject]?)->Bool{
//Overridepointforcustomizationafterapplicationlaunch.

NSLog("开始启动application........")

window=UIWindow(frame:UIScreen.mainScreen().bounds)
window?.backgroundColor=UIColor.orangeColor()


window?.rootViewController=ViewController()


returntrue
}

/*点击HOme键后,程序即将进入委托处理(委托给系统处理),紧跟着将会触发applicationDidEnterBackground方法*/
funcapplicationWillResignActive(application:UIApplication){
//Sentwhentheapplicationisabouttomovefromactivetoinactivestate.Thiscanoccurforcertaintypesoftemporaryinterruptions(suchasanincomingphonecallorSMSmessage)orwhentheuserquitstheapplicationanditbeginsthetransitiontothebackgroundstate.
//UsethismethodtopauSEOngoingtasks,disabletimers,andthrottledownOpenGLESframerates.Gamesshouldusethismethodtopausethegame.
NSLog("开始启动applicationWillResignActive........")
}
/*用户点击了Home按键,程序进入后台处理*/
funcapplicationDidEnterBackground(application:UIApplication){
//Usethismethodtoreleasesharedresources,saveuserdata,invalidatetimers,andstoreenoughapplicationstateinformationtorestoreyourapplicationtoitscurrentstateincaseitisterminatedlater.
//Ifyourapplicationsupportsbackgroundexecution,thismethodiscalledinsteadofapplicationWillTerminate:whentheuserquits.
NSLog("开始启动applicationDidEnterBackground........")
}

/*在应用程序未消亡状态,状态由后台处理,进入前台处理,触发该方法,之后触发applicationDidBecomeActive*/
funcapplicationWillEnterForeground(application:UIApplication){
//Calledaspartofthetransitionfromthebackgroundtotheinactivestate;hereyoucanundomanyofthechangesmadeonenteringthebackground.
NSLog("开始启动applicationWillEnterForeground........")
}
/*应用程序进入后,触发该方法*/
funcapplicationDidBecomeActive(application:UIApplication){
//Restartanytasksthatwerepaused(ornotyetstarted)whiletheapplicationwasinactive.Iftheapplicationwaspreviouslyinthebackground,optionallyrefreshtheuserinterface.
NSLog("开始启动applicationDidBecomeActive........")
}

funcapplicationWillTerminate(application:UIApplication){
//Calledwhentheapplicationisabouttoterminate.Savedataifappropriate.SeealsoapplicationDidEnterBackground:.
NSLog("开始启动applicationWillTerminate........")
}


}


转载至吴统威的博客:http://www.wutongwei.com/front/infor_showone.tweb?id=87

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读