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设置根视图控制器(现在只做了解)
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:.
}
}