zoukankan      html  css  js  c++  java
  • frame与bounds

    frame其实也是一个结构体,是结构体CGRect的一个变量。两个成员变量里分别有两个成员变量都是cgfloat类型的。

     

        

        UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 45, 50, 50)];

        view2.backgroundColor = [UIColor blueColor];

        [view addSubview:view2];

        

        [view2 release];

       UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 10)];

        view3.backgroundColor = [UIColor yellowColor];

        [view2 addSubview:view3];

        [view3 release];

    //  将视图插在指定的层数上

        //index数值 越小越靠后 0开始

       UIView * greenView = [[UIView alloc]initWithFrame:CGRectMake(60, 50, 50, 100)];

      greenView.backgroundColor = [UIColor greenColor];

      [self.window insertSubview:greenView atIndex:1];

       // 将第一个参数的视图 插入到第二个参数视图的后面

        [self.window insertSubview:RedView belowSubview:greenView];

        // 第一个参数视图 放到 第二个参数视图的上面

        [self.window insertSubview:greenView aboveSubview:RedView];

       // 将指定视图移动到最前面

        [self.window bringSubviewToFront:RedView];

        // 将指定视图移动到最后面

        [self.window sendSubviewToBack:RedView];

        // 将指定视图交换

        [self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

        

        // 将视图隐藏

      blueView.hidden=YES;

        // 调整视图的透明度

        RedView.alpha=0.5;

       [greenView release];

        

        //获取本视图的父视图

        UIView * test = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];

        [blueView addSubview:test];

        test.backgroundColor = [UIColor cyanColor];

       UIView * resu = [test superview];

        resu.backgroundColor = [UIColor blackColor];

        

        //获取本视图的子视图

       NSArray * subview = [blueView subviews];

       UIView * vie1 = subview[0];

       vie1.backgroundColor = [UIColor whiteColor];

            

        //给视图添加了标记 被添加完标记的视图 可以使用  viewWithTag 方法取出   数要大于100

        blueView.tag=101;

        UIView * vi =[self.window viewWithTag:101];

        vi.backgroundColor = [UIColor yellowColor];

        

        // 设置view 的圆角

      blueView.layer.masksToBounds=YES;

       // 每个角弯曲的半径是多少  方形才有可能变成圆圈

        blueView.layer.cornerRadius=75;

       

    //bounds

    在每添加一个view的时候,每个view分别以自己的起点为(0,0)点,创建一个坐标系,这个bounds就是一个结构体,用来确定view的新坐标。

     

        // bounds也是结构体,与frame一样。只是坐标是从自己的原点开始。

        // 当视图创建之后,会产生自己的一套坐标系。给自己的子视图用。起点也是左上角开始。

    frame与bounds的区别:

    frame与bounds都是结构体,都是用来确定位置和大小的;

    frame的位置是从屏幕的最左上角开始算的;

    bounds是从新添加的view的最左上角的点开始算   

  • 相关阅读:
    互联网、云大数据相关书籍推荐
    育儿、教育书籍推荐
    MySQL客户端工具的选择
    解决Windows10或者其他版本Windows Update报错的问题
    启动Myeclipse报错“Failed to create the Java Virtual Machine”的解决办法
    mysql的日期存储字段比较int,datetime,timestamp区别
    nginx增加ssl服务方法
    mysql导入出现MySQL Error 1153
    mysql忘记密码修改方法
    清空本地ssh记录数据,ssh: connect to host Ip port 22: Connection refused
  • 原文地址:https://www.cnblogs.com/Coder-GT/p/4865922.html
Copyright © 2011-2022 走看看