//应用程序代理类
//AppDelegate中的方法都是UIApplicationDelegatez的协议方法
//应用程序类
class AppDelegate: UIResponder, UIApplicationDelegate {
//应用程序窗口,是 AppDelete类的属性
var window: UIWindow?
//应用程序加载完成触发这个方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//想再window对象添加对象,就在这个方法中实现
//屏幕类UIScreen
//UIScreen.main获取屏幕对象
//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)
//让Window成为应用程序的主窗口,并使其可见
self.window?.makeKeyAndVisible()
//给window设置跟试图控制器(现在制作了解)
self.window?.rootViewController=UIViewController()
//一般应用程序只有一个window对象
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:.
}
}
何敏 14:54:55
class AppDelegate: UIResponder, UIApplicationDelegate {
//应用程序窗口,是 AppDelete类的属性
var window: UIWindow?
//应用程序加载完成触发这个方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//想再window对象添加对象,就在这个方法中实现
//屏幕类UIScreen
//UIScreen.main获取屏幕对象
//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)
//让Window成为应用程序的主窗口,并使其可见
self.window?.makeKeyAndVisible()
//给window设置跟试图控制器(现在制作了解)
self.window?.rootViewController=UIViewController()
//一般应用程序只有一个window对象
//UiView 创建方式
/*
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添加一个子视图
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中心点和window中心点重合
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值属性,给视图添加一个唯一标识
greenView.tag=200
self.window?.addSubview(greenView)
//subView属性,获取子视图属性
let arr=centerView.subviews
let newView=arr[0]
newView.backgroundColor=UIColor.blue
//根据tag值获取视图对象
let newView2=centerView.viewWithTag(200)
newView2?.backgroundColor=UIColor.gray
return true
}