zoukankan      html  css  js  c++  java
  • 关于bounds和frame的区别

    今天测试了一个关于bounds的demo,发现了之前一直不知道的问题

    // Do any additional setup after loading the view.
        UIView * view=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
        view.bounds=CGRectMake(-20, -20, 200, 200);
        NSLog(@"%f,%f",view.frame.origin.x,view.frame.origin.y);
    //    view.center=CGPointMake(160, 240);
        view.backgroundColor=[UIColor redColor];
        [self.view addSubview:view];
        UIView * l=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        l.backgroundColor=[UIColor cyanColor];
        [view addSubview:l];
    

      代码就是这么多。

    1.如果不设置view的frame。而只设置view的bounds,view的默认中心在原点上,也就是左上角。

    2.view的bounds的前边两个参数是代表本地坐标。也就是说如上边例子中  (-20 ,-20 )代表如view的左上角相对于view 自己的坐标,那么(0,0)就如下图所示

    在self。windows 的坐标系中从左上角坐标依次是 (0,0) ,(10,10)。。(30,30)

    在view自己的本地坐标系中,从左上角坐标依次是(-20,-20),(0,0);

  • 相关阅读:
    Spring Boot中Bean对象的核心特性及依赖注入分析
    Spring Boot快速入门
    throw和throws
    Spring框架中的一些常见注释
    关于maven的介绍并创建一个简单的maven工程
    luffyapi~settings
    爬虫~requests
    爬虫~scrapy1
    爬虫~scrapy
    爬虫~选择器
  • 原文地址:https://www.cnblogs.com/AbelChen1991/p/3674150.html
Copyright © 2011-2022 走看看