//
// AppDelegate.m
// UI01_UIView
//
// Created by lanou3g on 17/8/3.
// Copyright ? 2017年 lanou3g. All rights reserved.
//
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
//程序加載完成之后
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//單例:整個生命周期內(nèi)只有一個對象
[UIScreen mainScreen];
self.window.backgroundColor = [UIColor whiteColor];
//讓window作為主window并可見
[self.window makeKeyAndVisible];
//創(chuàng)建根視圖對象
RootViewController *rootViewController = [[RootViewController alloc] init];
//將window的根視圖設(shè)置為rootViewController
self.window.rootViewController = rootViewController;
NSLog(@"程序加載完成之后");
return YES;
}
//失去活躍狀態(tài)
- (void)applicationWillResignActive:(UIApplication *)application {
// 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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
NSLog(@"失去活躍狀態(tài)");
}
//程序進(jìn)入后臺
- (void)applicationDidEnterBackground:(UIApplication *)application {
// 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.
NSLog(@"程序進(jìn)入后臺");
}
//將要進(jìn)入前臺
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
NSLog(@"將要進(jìn)入前臺");
}
//成為活躍狀態(tài)
- (void)applicationDidBecomeActive:(UIApplication *)application {
// 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.
NSLog(@"成為活躍狀態(tài)");
}
//程序?qū)⒁Y(jié)束時
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
NSLog(@"程序?qū)⒁Y(jié)束時");
}
@end
//
// RootViewController.m
// UI01_UIView
//
// Created by lanou3g on 17/8/3.
// Copyright ? 2017年 lanou3g. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
//視圖加載完成(自帶的view)
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *redview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
redview.backgroundColor = [UIColor redColor];
//將redview添加到self.view上
[self.view addSubview:redview];
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
greenView.backgroundColor = [UIColor greenColor];
[self.view addSubview:greenView];
//中心點
greenView.center = CGPointMake(100, 100);
NSLog(@"%@",NSStringFromCGRect(greenView.frame));
//hidden 控制視圖隱藏
greenView.hidden = NO;
//alpha 視圖的透明度 (0是完全透明)
greenView.alpha = 0.5f;
//superview獲取本視圖的父視圖
NSLog(@"superView:%@",greenView.superview);
//superview獲取本視圖的所有子視圖
NSLog(@"subViews:%@",self.view.subviews);
//tag:給視圖一個標(biāo)記呢簸,用來找到該視圖(系統(tǒng)保留1000以內(nèi)凌那,為了避免沖突,所以我們tag賦值通常在1000以上)
greenView.tag = 1001;
UIView *tagView = [self.view viewWithTag:1001];
NSLog(@"%@",tagView);
UIView *orangeView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)];
orangeView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:orangeView];
//在指定的index處插入子視圖
// [self.view insertSubview:orangeView atIndex:1];
//在指定的視圖上面添加子視圖
[self.view insertSubview:orangeView aboveSubview:redview];
//從父視圖中移除
[orangeView removeFromSuperview];
//bunds會影響子視圖的位置 frame會影響父視圖的位置
}
//收到內(nèi)存警告
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end