bounds和frame的区别?

frame和bounds都市用来描述一块区域的

frame是以父控件的左上角为原点,可视范围相对于父控件

bounds:描述是可视范围在内容哪个区域,相对于内容.

           可视化区域在内容中显示区域,bounds的x,y可以改(改的是内容原点的位置)

任何控件都有自己的内容,而且这个内容无限大

子控件都市相对于内容

 

UIView *redView = [[UIView alloc] init];

    redView.frame = CGRectMake(50, 50, 200, 200);

    redView.backgroundColor = [UIColor redColor];

    [self.view addSubview:redView];

    _redView = redView;

    

    UISwitch *switchV = [[UISwitch alloc] init];

    [_redView addSubview:switchV];

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    CGRect bounds = _redView.bounds;

    bounds.origin.y += 10;

    _redView.bounds = bounds;

}

 

posted @ 2016-04-22 17:41  文健博客  阅读(282)  评论(0编辑  收藏  举报