@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)
self.window?.makeKeyAndVisible()
self.window?.rootViewController = UIViewController()
/*
//(UIView Layout) 視圖布局
//frame bounds center
//frame決定的是一個視圖,在他父視圖的位置
let redView = UIView(frame: CGRect(x: 10, y: 20, width: 100, height: 150))
redView.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)
self.window?.addSubview(redView)
redView.frame.origin = CGPoint(x: 100, y: 200)
redView.frame.size = CGSize(width: 200, height: 200)
// frame既能決定他在父視圖的位置,也能控制他在父視圖上的大小
print(UIScreen.main.bounds)
//bouds 視圖自身的邊界,bounds決定自身上子視圖的位置bouds的origin點默認和視圖本身坐標系的點是重合的
print(redView.bounds)
let greenView = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))
greenView.backgroundColor = UIColor.green
redView.addSubview(greenView)
//不修改bounds的size, 修改bounds的origin
redView.bounds.origin = CGPoint(x: 50, y: 50)
print("中心點:\(redView.center)")
//無論一個視圖的bounds怎么改變,這個視圖的中心點都不會改變
*/
//視圖層級關系
let a = UIView(frame: CGRect(x: 157, y: 200, width: 100, height: 100))
a.backgroundColor = #colorLiteral(red: 0.9568627477, green: 0.6588235497, blue: 0.5450980663, alpha: 1)
self.window?.addSubview(a)
let b = UIView(frame: CGRect(x: 107, y: 150, width: 200, height: 200))
b.backgroundColor = #colorLiteral(red: 0.721568644, green: 0.8862745166, blue: 0.5921568871, alpha: 1)
self.window?.addSubview(b)
//最后添加在上層
//視圖a放在最上層顯示
//self.window?.bringSubview(toFront: a)
//視圖b放在最下層
//self.window?.sendSubview(toBack: b)
//刪除視圖b
//b.removeFromSuperview()
print(self.window?.subviews)
//? ? ? ? self.window?.exchangeSubview(at: <#T##Int#>, withSubviewAt: <#T##Int#>)
return true
}