uiview子视图Center中心点2,层层叠加子视图,release与removeFromSuperview区别

    /*

     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;

        

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值