uikit——UIView——bounds frame
来源:互联网 发布:linux中etc是什么意思 编辑:程序博客网 时间:2024/06/13 22:07
coordinate system
// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.@property(nonatomic) CGRect frame;// use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part@property(nonatomic) CGRect bounds; // default bounds is zero origin, frame size. animatable@property(nonatomic) CGPoint center; // center is center of frame. animatable@property(nonatomic) CGAffineTransform transform; // default is CGAffineTransformIdentity. animatable
解释:
- frame:参考父view坐标系
- bounds:参考view自身坐标系
- center:参考父view坐标系
注1:view尺寸与坐标系无关,即frame.size和bound.size恒一致
注2:独立改变frame.size不改变center,frame.size改变以center为中心四周均匀变化
应用
- (void)showView{ self.view.backgroundColor = [UIColor purpleColor]; { UIView *parent = [[UIView alloc] initWithFrame:CGRectMake(60, 30, 200, 160)]; UIView *sub = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; parent.backgroundColor = [UIColor blueColor]; sub.backgroundColor = [UIColor brownColor]; [self.view addSubview:parent]; [parent addSubview:sub]; } { UIView *parent = [[UIView alloc] initWithFrame:CGRectMake(60, 210, 200, 160)]; UIView *sub = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; parent.backgroundColor = [UIColor blueColor]; sub.backgroundColor = [UIColor brownColor]; [self.view addSubview:parent]; [parent addSubview:sub]; CGRect bounds = parent.bounds; bounds.origin = CGPointMake(20, 20); parent.bounds = bounds; } { UIView *parent = [[UIView alloc] initWithFrame:CGRectMake(60, 390, 200, 160)]; UIView *sub = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; parent.backgroundColor = [UIColor blueColor]; sub.backgroundColor = [UIColor brownColor]; [self.view addSubview:parent]; [parent addSubview:sub]; CGRect bounds = parent.bounds; bounds.origin = CGPointMake(-20, -20); parent.bounds = bounds; }}
总结:
- 子view左上角pos相对于父view左上角pos的offset为子view.frame.origin减去父view.bounds.origin,即子view在父坐标系中pos减去父view在自身坐标系中pos
注:bounds.origin改变本质是改变view自身坐标系原点(子view参考坐标系),因此会影响子view显示
0 0
- uikit——UIView——bounds frame
- cocoa touch——UIView——frame bounds center
- IOS-Frameworks-UIKit-UIView.h-frame属性和bounds属性
- uikit——UIView——drawing
- uikit——UIView——layout
- uikit——UIView——autoresizing
- uikit——UIView——content
- uikit——UIView——tag
- uikit——UIView——event
- uikit——UIView——appearance
- uikit——UIView——resizing
- UIKit框架 -UIView and frame和bounds之区别(位置和大小)
- IOS界面开发基础——Frame与Bounds
- iOS项目开发实战——理解frame,bounds,center
- iOS开发——frame和bounds详解
- iOS开发——frame和bounds详解
- iOS开发——frame和bounds详解
- iOS —— bounds vs frame vs center
- 1044. 火星数字(20)
- 无GPU条件下安装caffe
- Spring MVC @SessionAttribute 使用
- MySQL 大数据量快速插入方法和语句优化
- leetcode | 1. Two sum 解题报告
- uikit——UIView——bounds frame
- Sqoop从Oracle导入表到Hive
- LeetCode笔记:46. Permutations
- URL中“#” “?” &“”号的作用
- ajax同步异步 async默认为true 异步 async:false, //同步
- 前端必须会的5个原生JavaScript对象方法
- 读取网络时间完整代码
- 技术揭秘QQ空间”自动转发不良信息
- mysql索引(二)