class AppDelegate: UIResponder, UIApplicationDelegate {
//應(yīng)用程序窗口,是AppDelegate類的屬性
var window: UIWindow?
//lazy var array:[Int] = Array()
//應(yīng)用程序加載完成時(shí)觸發(fā)這個(gè)方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//想再window對(duì)象添加內(nèi)容,就在這個(gè)方法中實(shí)現(xiàn)
//UIScreen屏幕類
//UIScreen.main獲取屏幕對(duì)象
//UIScreen.main.bounds獲取當(dāng)前設(shè)備屏幕大小
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1)//輸入color 回車? = UIColor.green
//使window成為應(yīng)用程序主窗口并使其可見(jiàn)
self.window?.makeKeyAndVisible()
//給window設(shè)置根視圖控制器(現(xiàn)在只做了解)
self.window?.rootViewController = UIViewController()
//一般應(yīng)用程序只有一個(gè)UIWindow對(duì)象
//UIView的創(chuàng)建方式
//1.創(chuàng)建一個(gè)子視圖 左上角
/*
let radView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
radView.backgroundColor = #colorLiteral(red: 1, green: 0.2527923882, blue: 1, alpha: 1)
//向window上添加一個(gè)子視圖
self.window?.addSubview(radView)
//獲取屏幕的寬和高
let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
//2.創(chuàng)建一個(gè)子視圖 右上角
let greenView = UIView(frame: CGRect(x: screenWidth - 100, y: 0, width: 100, height: 100))
greenView.backgroundColor = UIColor.green
//向window上添加一個(gè)子視圖
self.window?.addSubview(greenView)
//3.創(chuàng)建一個(gè)子視圖 右下角
let magentaView = UIView(frame: CGRect(x: screenWidth - 100, y: screenHeight - 100, width: 100, height: 100))
magentaView.backgroundColor = UIColor.darkGray
self.window?.addSubview(magentaView)
//4.創(chuàng)建一個(gè)子視圖 左下角
let purpleView = UIView(frame: CGRect(x: 0, y: screenHeight - 100, width: 100, height: 100))
purpleView.backgroundColor = UIColor.brown
self.window?.addSubview(purpleView)
//5.創(chuàng)建一個(gè)子視圖 中心點(diǎn)
let yellowView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
//yellowView中心點(diǎn)和window中心點(diǎn)重合
yellowView.center = (self.window?.center)!
yellowView.backgroundColor = #colorLiteral(red: 0.9686274529, green: 0.78039217, blue: 0.3450980484, alpha: 1)
self.window?.addSubview(yellowView)
*/
let centerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
centerView.backgroundColor = #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)
self.window?.addSubview(centerView)
//UIView的常用屬性
//alpha 透明度 0.0--1.0? 1.0完全不透明
centerView.alpha = 1.0
//hidden顯示隱藏? 顯隱性? true是隱藏 false顯示(默認(rèn)的)
centerView.isHidden = false
//superView 超視圖獲取到父視圖的屬性
let fatherView = centerView.superview
fatherView?.backgroundColor = UIColor.green
//向centerview上添加子視圖
let greenView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
greenView.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
//子視圖超出父視圖的邊界就把超出的部分剪掉(了解)
//centerView.clipsToBounds = true
//tag值屬性 給一個(gè)視圖添加一個(gè)唯一標(biāo)識(shí)(0~100內(nèi)不再使用)
greenView.tag = 200//整數(shù)值
centerView.addSubview(greenView)
//獲取subview屬性,獲取子視圖屬性 只能有一個(gè)父視圖 多個(gè)子視圖,返回值是一個(gè)數(shù)組,數(shù)組元素有序
let arr = centerView.subviews
let newView = arr[0]
newView.backgroundColor = #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)
//根據(jù)tag值獲取視圖對(duì)象
let newView2 = centerView.viewWithTag(200)
newView.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
//? ? ? ? let newView3 = centerView.viewWithTag(200)
//? ? ? ? newView.backgroundColor = #colorLiteral(red: 0.521568656, green: 0.1098039225, blue: 0.05098039284, alpha: 1)
return true
}
//應(yīng)用程序?qū)⒁∠钴S狀態(tài)時(shí)觸發(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)的時(shí)候觸發(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.
}
//程序?qū)⒁Y(jié)束的時(shí)候觸發(fā)
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}