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

前端之家收集整理的这篇文章主要介绍了The Swift Code之应用程序的启动过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

原文链接:/swift/327319.html

猜你在找的Swift相关文章