AppDelegate相当于程序的入口,在这里可以初始化程序。可以给页面上添加window,controller,view等 。
//
// AppDelegate.swift
// reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//程序载入后执行
print("didFinishLaunchingWithOptions:程序载入")
return true
}
func applicationWillResignActive(_ application: UIApplication) {
//当应用程序从活动状态到非活动状态,这个发生在突然的打断,比如来电话。或者短信,或者当用户推出应用程序。过渡到后台状态
//用这个方法暂停正在进行的任务,禁用计时器 。游戏用这个方法来暂停游戏
print("applicationWillResignActive 程序中断")
}
func applicationDidEnterBackground(_ application: UIApplication) {
//当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可
//用这个方法来释放共享的资源 , 保存用户数据 ,停用计时器。
print("applicationDidEnterBackground 程序在后台运行")
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
//当程序从后台将要重新回到前台时候调用,你取消进入后台的时候调用的程序
print("applicationWillEnterForeground 从后台回到前台了")
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
//当应用程序处于非活动状态时,重启暂停(或尚未启动)的任何任务。如果应用程序先前在后台,则可以选择刷新用户界面。
print("applicationDidBecomeActive 程序开始正常运行了")
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
//应用程序将要被终结的时候执行,可以适当保存数据之类的
print("applicationWillTerminate 程序将要被终结了")
}
func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
//如果程序内存溢出,操作系统会终止程序的执行,在终止之前会执行这个方法,通常可以在这里进行内存清理的工作防止程序被终止
print("applicationDidReceiveMemoryWarning 内存溢出了,程序准备终止")
}
func applicationSignificantTimeChange(_ application: UIApplication) {
//当系统时间发生改变时的执行
print("applicationSignificantTimeChange 系统时间发生改变了")
}
func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) {
//当StatusBar框将要变化时执行
print("application-willChangeStatusBarFrame 执行了")
}
}