import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//UIScreen.main.bounds獲取當前設備屏幕大小
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = #colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1)
//使window成為成為應用程序主窗口并使其可見
self.window?.makeKeyAndVisible()
//給window設置根視圖控制器(現(xiàn)在只做了解)
self.window?.rootViewController = UIViewController()
/*
//UIView layout 視圖布局
//frame bounds center
//frame決定的是一個視圖庸诱,在他父視圖的位置
let redView = UIView(frame: CGRect(x: 10, y: 20, width: 100, height: 200))
redView.backgroundColor = #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1)
self.window?.addSubview(redView)
//frame技能決定它在父視圖的位置孕似,也能控制它在父視圖上的大小
redView.frame.origin = CGPoint(x: 100, y: 200)
redView.frame.size = CGSize(width: 200, height: 200)
//輸出當前屏幕的大小
print(UIScreen.main.bounds)
//bounds 視圖自身的邊界,bounds決定自身上子視圖的位置 以redview為坐標母截,bounds的origin點默認和視圖本身的坐標系的原點是重合的
print(redView.bounds)
let greenView = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))
greenView.backgroundColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
redView.addSubview(greenView)
//不修改bounds的size修改bounds的origin
print("中心點:\(redView.center)")
redView.bounds.origin = CGPoint(x: 50, y: 50 )
print("中心點:\(redView.center)")
print(greenView.frame)
//無論視圖的bounds怎么改變脂矫,這個視圖的中心點都不會改變
*/
//視圖的層級關系
let a = UIView(frame: CGRect(x: 157, y: 200, width: 100, height: 100))
a.backgroundColor = #colorLiteral(red: 0.5568627715, green: 0.3529411852, blue: 0.9686274529, alpha: 1)
self.window?.addSubview(a)
let b = UIView(frame: CGRect(x: 107, y: 150, width: 200, height: 200))
b.backgroundColor = #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)
self.window?.addSubview(b)
//誰最后添加誰就在最上層
//1.將視圖a放在最上層顯示
//self.window?.bringSubview(toFront: a)
//2.將視圖b放在最下層顯示
//self.window?.sendSubview(toBack: b)
//3.刪除最后添加的視圖b
//b.removeFromSuperview()
//4.交換兩個視圖
//print(self.window?.subviews)
self.window?.exchangeSubview(at: 1, withSubviewAt: 2)
return true
}
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.
}
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.
}
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.
}
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.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}