/*
UIView:
坐标相关属性:frame 位置 大小 bounds (以自身为参考坐标 起始点 (0,0)) center中心点(相对于父视图而言)
UIView只能有一个父视图 可以有多个子视图
*/
UIView *v =[[UIView alloc] initWithFrame:CGRectMake(0, 20, 200, 200)];
v.backgroundColor = [UIColor orangeColor];
[self.window addSubview:v];
[v release];
NSLog(@"%f %f",v.center.x,v.center.y);
UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 200, 200)];
[v addSubview:v1];
[v1 release];
NSLog(@"%f %f",v1.center.x,v1.center.y);
//获取当前视图的父视图
//将某个视图隐藏
//v1.hidden =YES;
//将当前父视图上 超出父视图边界的子视图部分剪裁方法
// v.clipsToBounds = YES;
//将子视图从父视图中移除
[v1 removeFromSuperview];
SubView *v2 = [[SubView alloc] initWithFrame:CGRectMake(150, 150, 150, 150)];
v2.backgroundColor =[UIColor greenColor];
[self.window addSubview:v2];
SubView *v3 = [[SubView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[v2 addSubview:v3];
[v3 release];
/*
removeFromSuperview:将子视图从父视图当中移除,同时将它从响应者链中移除
会对该对象响应者链之下的所有子视图做一次release
release:仅仅只对对象的引用计数减1
*/
[v2 release];
[v2 removeFromSuperview];
//中间打印图片
// for (int i =0; i<11; i++) {
// UIView *vx = [[UIView alloc] initWithFrame:CGRectMake(50 +i*10, 145 +i*10, 220 - 20*i, 220 - 20*i)];
// vx.backgroundColor = [[UIColor alloc] initWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:arc4random()%1000/999.0];
// //改变Certer会影响frame
// [self.window addSubview:vx];
//
// [vx release];
// }
// UIView *v5 =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 400)];
// v5.backgroundColor = [[UIColor alloc] initWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:arc4random()%1001/999.0];
// v5.center = CGPointMake(160, 240);
// [self.window addSubview:v5];
// UIView *v6 = v5;
// for (int i= 0; i <10; i++) {
// UIView *v7 =[[UIView alloc] initWithFrame:CGRectMake(0, 0, v6.frame.size.width-20, v6.frame.size.height - 20)];
// v7.center = CGPointMake(v6.frame.size.width/2, v6.frame.size.height/2);
// v7.backgroundColor = [[UIColor alloc] initWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:arc4random()%1001/999.0];
// [v6 addSubview:v7];
// v6 = [v7 retain];
// [v7 release];
// }
UIView *tempView = self.window;
for (int i =0; i<10; i++) {
UIView *v =[[UIView alloc] initWithFrame:CGRectMake(0, 0, tempView.frame.size.width- 40,tempView.frame.size.height- 30 )];
v.backgroundColor =[[UIColor alloc] initWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
v.center =CGPointMake(tempView.frame.size.width/2.0, tempView.frame.size.height/2.0);
[tempView addSubview:v];
[v release];
tempView = v;
}