zoukankan      html  css  js  c++  java
  • 【iOS基础学习随笔-3】frame与bounds到底有什么联系

    先说一下网上其他博客抄来抄去也就算了,关键是我都怀疑你抄完了以后你懂了么?自己都不懂抄过来让谁看呢?

        UIButton *subView = [UIButton buttonWithType:UIButtonTypeCustom];

        subView.frame = CGRectMake(0, 0, 200, 200);

        [subView addTarget:self action:@selector(dianji) forControlEvents:UIControlEventTouchUpInside];

        [subView setBounds:CGRectMake(-20, -20, 100, 100)];

        subView.backgroundColor = [UIColor redColor];

        [self.view addSubview:subView];

        NSLog(@"--%@",NSStringFromCGRect(subView.frame));

        

        UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

        view1.backgroundColor = [UIColor greenColor];

        view1.alpha = 0.5;

        [subView addSubview:view1];

     

     

    subView在setBounds后发生如下变化

    1、subView原先的左上交的点的坐标点为(0,0),现在为(-20,-20),所以view1现在的效果相当于原来的(20,20,100,100),实际上view1的frame并没有改变,只是效果变了

    2、subView大小缩小为剧中缩小,新的frame为(50,50,100,100),这个50 是原来的宽(高)减去现在的宽(高)除以2(因为前后都一样才算是剧中缩小)得出的。发生这种变化的原因我也不清楚,这个结果是试验出来的。

     

     

     

    网上大多只说了第一种情况而没说第二种情况。

  • 相关阅读:
    Get distinct count of rows in the DataSet
    单引号双引号的html转义符
    PETS Public English Test System
    Code 39 basics (39条形码原理)
    Index was outside the bounds of the array ,LocalReport.Render
    Thread was being aborted Errors
    Reportviewer Error: ASP.NET session has expired
    ReportDataSource 值不在预期的范围内
    .NET/FCL 2.0在Serialization方面的增强
    Perl像C一样强大,像awk、sed等脚本描述语言一样方便。
  • 原文地址:https://www.cnblogs.com/Hanzo/p/6048241.html
Copyright © 2011-2022 走看看