#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];;
//320*568 5s
//创建一个宽高为200的视图,添加到屏幕的中间
//视图的位置是相对于父视图左边原点的位置
//UIView 重要属性
//1.frame包含orgin(左上角坐标),seze(矩形的大小)
//2.center 视图相对对父视图坐标系的中心点
//3.bounds 发生变化,影响的是自身坐标系的坐标原点,进而影响子视图的位置变化
// UIView *centerView = [[UIView alloc] initWithFrame:CGRectMake(60,184, 200, 200)];
// [self.window addSubview:centerView];
// centerView.backgroundColor = [UIColor redColor];
//
// [centerView release];
//
//
// //更改centerview相对自身坐标系的位置
// //centerView自己位置没有遍,bounds改变的是centeView自己的坐标原点
// //造成centerView字视图的位置改变
// centerView.bounds = CGRectMake(50, 50, 200, 200);
//
//
// //创建一个宽高为100的视图,添加到屏幕的中间
// UIView *centerView1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
// [centerView addSubview:centerView1];
// centerView1.backgroundColor = [UIColor greenColor];
//
// [centerView1 release];
//
UIView *centerView1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
[self.window addSubview:centerView1];
centerView1.backgroundColor = [UIColor redColor];
[centerView1 release];
UIView *centerView2 = [[UIView alloc] initWithFrame:CGRectMake(50+80, 50+80, 100, 100)];
[self.window addSubview:centerView2];
centerView2.backgroundColor = [UIColor greenColor];
[centerView2 release];
UIView *centerView3 = [[UIView alloc] initWithFrame:CGRectMake(50+80+80, 50+80+80, 100, 100)];
[self.window addSubview:centerView3];
centerView3.backgroundColor = [UIColor yellowColor];
[centerView3 release];
UIView *centerView4 = [[UIView alloc] initWithFrame:CGRectMake(50+80, 50+80+80+80, 100, 100)];
[self.window addSubview:centerView4];
centerView4.backgroundColor = [UIColor grayColor];
[centerView4 release];
UIView *centerView5 = [[UIView alloc] initWithFrame:CGRectMake(50, 50+80+80+80+80, 100, 100)];
[self.window addSubview:centerView5];
centerView5.backgroundColor = [UIColor orangeColor];
[centerView5 release];
//打印brownView的父视图
NSLog(@"%@",centerView1.superview);
//打印window的子视图
NSLog(@"%@",self.window.subviews);
//创建一个灰色视图
UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
blackView.backgroundColor = [UIColor blackColor];
[self.window addSubview:blackView];
//将视图插入指定位置
//[self.window insertSubview:blackView atIndex:0];
//在指定视图的下面
//[self.window insertSubview:blackView belowSubview:centerView1];
//在指定视图的上面
//[self.window insertSubview:blackView aboveSubview:centerView1];
[blackView release];
//交换两个视图
//[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//将视图移到最前面
//[self.window sendSubviewToBack:centerView1];
//将视图移到最后面
//[self.window bringSubviewToFront:centerView2];
//删除指定视图
//[centerView2 removeFromSuperview];
//视图间的层级关系
//1.子视图肯定会在父视图的前面
//2.后添加的视图如果和之前的视图有重叠的部分,会覆盖掉之前的视图
//3.如果要插入或者改变视图的层级关系,都需要父视图来管理
//4.父视图通过数组来管理子视图的层级关系
//5.如果想从父视图上移除,自己移除即可 例如[centerView2 removeFromSuperview];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}