zoukankan      html  css  js  c++  java
  • UI部分bounds和frame

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        //设置viewController的背景色,准确的说,我们是设置viewController的View的背景色
        self.view.backgroundColor=[UIColor magentaColor];
        
        //新建一个UIView
        
        UIView *blackView=[[UIView alloc] initWithFrame:CGRectMake(10, 100, 200, 100)];
        
        NSLog(@"修改bounds坐标前的frame:%f   %f",blackView.frame.origin.x,blackView.frame.origin.y);
        NSLog(@"修改bounds坐标前的bounds:%f   %f",blackView.bounds.origin.x,blackView.bounds.origin.y);
        //设置View背景色为黑色
        blackView.backgroundColor=[UIColor blackColor];
        
        [self.view addSubview:blackView];
        
        [blackView release];
        
        //再新一个View
        UIView *redView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 50)];
    //    
    //    NSLog(@"创建redView时的frame坐标:%f   %f",redView.frame.origin.x,redView.frame.origin.y);
    //    NSLog(@"创建redView时的bounds坐标:%f   %f",redView.bounds.origin.x,redView.bounds.origin.y);
        //设置View的背景色
        redView.backgroundColor=[UIColor redColor];
        
        [blackView addSubview:redView];
        
        [redView release];
        
        //bounds相对于本视图的坐标系
        //默认的是左上角坐标(0,0)
        
        //打印blackView的bounds
        
        //NSLog(@"%f--%f",blackView.bounds.origin.x,blackView.bounds.origin.y);
        
        //修改blackView的bounds左上角坐标,宽度和高度不变
        blackView.bounds=CGRectMake(-20, -20, blackView.bounds.size.width, blackView.bounds.size.height);
      //  NSLog(@"%f--%f",redView.frame.size.width,redView.frame.size.height);
        
        NSLog(@"修改blackView坐标前的frame:%f    %f",blackView.frame.origin.x,blackView.frame.origin.y);
        NSLog(@"修改blackView坐标前的bounds:%f   %f",blackView.bounds.origin.x,blackView.bounds.origin.y);
    //    NSLog(@"修改blackView后redView的frame坐标:%f   %f",redView.frame.origin.x,redView.frame.origin.y);
    //    NSLog(@"修改blackView后redView的bounds坐标:%f   %f",redView.bounds.origin.x,redView.bounds.origin.y);
        
    }

    此部分 修改外层坐标之前 之后 结果为

    可以看出 frame 是绝对的 不随bounds的改变而变化 子类视图坐标 不随父类视图的坐标变化而变化  自身移动会修改自身在父类视图中的位置

  • 相关阅读:
    开发思路总结
    电脑蓝屏代码丢失,Eclipse这个功能帮我找回了代码
    书籍
    向日葵无法在控制端用键盘输入的原因
    js 多submit 不使其执行其他submit form
    js获取url参数值
    C# 正则表达式 去除HTML标签 C#后台
    读取txt文件 循环操作每行数据 添加到数据库
    Ubuntu中安装XAMPP出错的解决方法(转发,备查)
    常用正则表达式
  • 原文地址:https://www.cnblogs.com/rainwz/p/4597400.html
Copyright © 2011-2022 走看看