zoukankan      html  css  js  c++  java
  • bounds、frame、contentoffset及contentSize和contentInset的新认识

    1、矩形框:控件自己的显示位置和尺寸(相当于frame)。
    2、内容:控件内部的东西,比如它的子控件(相当于bounds,如果bounds改变它的内容或控件的位置就会发生变化)。
    3、bounds:以控件自己内容的左上角为坐标点,计算出来的矩形框的位置和大小 。
    4、frame:以父控件内容的左上角为坐标原点,计算出来的矩形框的位置和大小。

    - (void)viewDidLoad {
        [super viewDidLoad];
        UIView *redView = [[UIView alloc] init];
        redView.backgroundColor = [UIColor redColor];
        [redView setFrame:CGRectMake(100, 200, 300, 300)];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
        [label setBackgroundColor:[UIColor blueColor]];
        [redView addSubview:label];
        [self.view addSubview:redView];
        self.redView = redView;
        //frame 是相当于框架
        //bounds 相当于内容
    }
    //touch began
    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
        CGRect bounds = self.redView.bounds;
        bounds.origin = CGPointMake(-50, -50);
        self.redView.bounds = bounds;
        //orgion变了,bounds中内容会发生改变,但frame框架没有改变,所以self.redView还没变
        //随着bounds的改变self.redViwiew的子控件Label会发生变化
    }

    5、UIScrollView的CGpoint与view视图的bounds一样。

    6、 contentInset内边距

       6.1 但凡是属于ScrollView或ScrollView的子类在遇到页面有导航或导航和tabBar都会自动添加64的间距,比如UITableViewController

       6.2 关闭自动适应约束

     // @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES,默认是添加自动适应的
        self.automaticallyAdjustsScrollViewInsets = NO;
    

    64,且只会对第一个继承自UIScrollViewf起作用。

     穿透效果就是这么做成的

    总结:当tableVIew顶部间距不对,或者尾部显示不到位,都可以通过ContentInset来设置
    
    将来的自己,会感谢现在不放弃的自己!
  • 相关阅读:
    java获取客户端用户真实ip
    electron制作上位机软件篇(三)启动项目并进行打包
    electron制作上位机软件篇(二)使用serialport进行串口通信
    electron制作上位机软件篇(一):编译安装serialport
    STM32学习篇-蜂鸣器
    STM32学习篇-跑马灯
    日志级别的选择:Debug、Info、Warn、Error还是Fatal
    常用的正则验证
    kindEditor富文本编辑器
    表单验证jq.validate.js
  • 原文地址:https://www.cnblogs.com/TheYouth/p/6528203.html
Copyright © 2011-2022 走看看