//應(yīng)用程序代理類
//AppDelegate中的方法都是UIApplicationDelegatez的協(xié)議方法
//應(yīng)用程序類
class AppDelegate: UIResponder, UIApplicationDelegate {
//應(yīng)用程序窗口,是 AppDelete類的屬性
var window: UIWindow?
//應(yīng)用程序加載完成觸發(fā)這個(gè)方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//想再window對(duì)象添加對(duì)象鹃锈,就在這個(gè)方法中實(shí)現(xiàn)
//屏幕類UIScreen
//UIScreen.main獲取屏幕對(duì)象
//UIScree.main.bounds
self.window=UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green: 0.8069495559, blue: 0.5823518634, alpha: 1)
//讓W(xué)indow成為應(yīng)用程序的主窗口笋熬,并使其可見(jiàn)
self.window?.makeKeyAndVisible()
//給window設(shè)置跟試圖控制器(現(xiàn)在制作了解)
self.window?.rootViewController=UIViewController()
//一般應(yīng)用程序只有一個(gè)window對(duì)象
return true
}
//應(yīng)用程序?qū)⒁∠钴S狀態(tài)是觸發(fā)
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
//已經(jīng)進(jìn)入后臺(tái)是觸發(fā)
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
//將要進(jìn)入前臺(tái)時(shí)觸發(fā)
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.
}
//應(yīng)用程序已經(jīng)變得活躍時(shí)觸發(fā)
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.
}
//將要結(jié)束觸發(fā)
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
何敏? 14:54:55
class AppDelegate: UIResponder, UIApplicationDelegate {
//應(yīng)用程序窗口,是 AppDelete類的屬性
var window: UIWindow?
//應(yīng)用程序加載完成觸發(fā)這個(gè)方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//想再window對(duì)象添加對(duì)象点楼,就在這個(gè)方法中實(shí)現(xiàn)
//屏幕類UIScreen
//UIScreen.main獲取屏幕對(duì)象
//UIScree.main.bounds
self.window=UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor=#colorLiteral(red: 0.5087699294, green: 0.8069495559, blue: 0.5823518634, alpha: 1)
//讓W(xué)indow成為應(yīng)用程序的主窗口,并使其可見(jiàn)
self.window?.makeKeyAndVisible()
//給window設(shè)置跟試圖控制器(現(xiàn)在制作了解)
self.window?.rootViewController=UIViewController()
//一般應(yīng)用程序只有一個(gè)window對(duì)象
//UiView 創(chuàng)建方式
/*
let redView=UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
redView.backgroundColor=#colorLiteral(red: 1, green: 0.3980397582, blue: 0.7863847613, alpha: 1)
//向window添加一個(gè)子視圖
self.window?.addSubview(redView)
//獲取屏幕的寬
let screenWidth = UIScreen.main.bounds.size.width
//獲取屏幕的高
let screenHeight=UIScreen.main.bounds.size.height
let greenView = UIView(frame: CGRect(x: screenWidth-100, y: 0, width: 100, height: 100))
greenView.backgroundColor=UIColor.green
self.window?.addSubview(greenView)
let blueView=UIView(frame: CGRect(x: 0, y: screenHeight-100, width: 100, height: 100))
blueView.backgroundColor=#colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)
self.window?.addSubview(blueView)
let yellowView = UIView(frame: CGRect(x: screenWidth-100, y: screenHeight-100, width: 100, height: 100))
yellowView.backgroundColor=UIColor.yellow
self.window?.addSubview(yellowView)
let purpleView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
//purpleView中心點(diǎn)和window中心點(diǎn)重合
purpleView.center=(self.window?.center)!
purpleView.backgroundColor=#colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
self.window?.addSubview(purpleView)*/
let centerView=UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
centerView.backgroundColor=UIColor.red
self.window?.addSubview(centerView)
//UIView常用屬性
//alpha 透明度 0.0~1.0
centerView.alpha=1.0
//hidden顯示隱形 true? 隱藏 false 顯示
centerView.isHidden=false
//superView獲取到父視圖的屬性
let fatherView=centerView.superview
fatherView?.backgroundColor=UIColor.yellow
//像centerView添加子視圖
let greenView=UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
greenView.backgroundColor=UIColor.green
//子視圖超出父視圖邊界,就把超出部分剪掉
//centerView.clipsToBounds=true
//tag值屬性膊夹,給視圖添加一個(gè)唯一標(biāo)識(shí)
greenView.tag=200
self.window?.addSubview(greenView)
//subView屬性,獲取子視圖屬性
let arr=centerView.subviews
let newView=arr[0]
newView.backgroundColor=UIColor.blue
//根據(jù)tag值獲取視圖對(duì)象
let newView2=centerView.viewWithTag(200)
newView2?.backgroundColor=UIColor.gray
return true
}