文章摘要:http://www.sendong.com/news1733.html
bounds是指这个view在它自己坐标系的坐标和大小 而frame指的是这个view在它superview的坐标系的坐标和大小
区别主要在坐标系这一块。
很明显一个是自己为原点的坐标系,一个是以屏 幕为原点的坐标系。绝对坐标。。。相对坐标。。。比如屏幕旋转的时候就要以相对来重绘。
frame 如果一个按钮,是在表格里,按钮的frame 的坐标也是相对的,并不是相对屏幕,也就是说是相对坐标,不是绝对坐标
我也想知道任何一个uiview如何求得它在屏幕上的坐标。
view 的frame是view在它的super view 的位置与尺寸。
view
的bounds可以用来帮助它的subview来定位的 ,layoutSubviews。
Frame is in terms of
superview's coordinate system
框架是从父视图的坐标系统
Bounds is in terms
of local coordinate system
是在局部坐标系统。
frame和bounds是UIView中的两个属性(property)。
frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统)
bounds指的是:该view在本身坐标系统中 的位置和大小。(参照点是本身坐标系统)
ios视图frame和bounds的区别:
bounds坐标:自己定义的坐标系统,setbound指明了本视图左上角在该坐标系统中的坐标,
默认值(0,0)
frame坐标: 子视图左上角在父视图坐标系统(bounds坐标系统)中的坐标,默认值(0,0)
子视图实际位置=父视图实际位置-父视图bounds坐标+子视图frame坐标
一、bounds
只影响“子视图”相对屏幕的位置,修改时不会影响自身相对屏幕的位置
1、父视图bounds坐标为(0,0)时
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
}
2、父视图bounds坐标为(-20,-20)时
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
[self.view setBounds:CGRectMake(-20, -20, 320, 568)];
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
}
二、frame
修改时改变了自己的在父视图坐标系统(bounds坐标系统)的位置,自身位置和
子视图位置都会被改变。
1、父视图frame坐标(0,0)
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view2.backgroundColor = [UIColor yellowColor];
[view1 addSubview:view2];
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds));
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view2.frame),NSStringFromCGRect(view2.bounds));
}
2、父视图frame坐标(60,60)
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view2.backgroundColor = [UIColor yellowColor];
[view1 addSubview:view2];
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds));
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(view2.frame),NSStringFromCGRect(view2.bounds));
}
三、说明
根视图只能修改bounds坐标,而不可以修改frame坐标
以下self.view为根视图
1、初始状态
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
}
2、修改bounds坐标:有效
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
CGRect viewBounds = self.view.bounds;
viewBounds.origin.y=-40;
viewBounds.origin.x=-40;
self.view.bounds=viewBounds;
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
}
3、修改frame坐标:无效
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 260)];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
CGRect viewFrame = self.view.frame;
viewFrame.origin.y=60;
viewFrame.origin.x=60;
self.view.frame=viewFrame;
NSLog(@"view frame:%@========view bounds:%@",NSStringFromCGRect(self.view.frame),NSStringFromCGRect(self.view.bounds));
}

- iOS开发中frame与bounds的区别
闲话不多说,先上两张图,大伙们就已经明白了: 显示出来的效果是这样子滴: 总结: 要理清这两者的区别,最主要的要理解一下几个概念:frame可以理解为可视的范围,而bounds可以理解为可视范围内的 ...
- iOS开发 frame 与 bounds 的区别与关系 转自隔叶黄莺
frame和bounds是UIView中的两个属性(property). frame指的是:该view在父view坐标系统中的位置和大小.(参照点是父亲的坐标系统) bounds指的是:该view在本 ...
- 【iOS】Frame和Bounds的区别以及获取绝对坐标的办法
终于搞清楚了,UIView中的frame获取的是相对于所在ParentView的坐标,而bounds则是指UIView本身的坐标.比如下图(假设A是屏幕): View B的Frame坐标是指相对于Vi ...
- iOS开发-View中frame和bounds区别
开发中调整View的时候的经常会遇到frame和bounds,刚开始看的时候不是很清楚,不过看了一下官方文档,frame是确定视图在父视图中的位置,和本身的大小,bounds确定可以确定子视图在当前视 ...
- iOS View的Frame和bounds之区别,setbounds使用(深入探究)
前言: 在ios开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bound的区别,尤其是bound很绕,较难理解. 一.首先,看一下公认的资料: 先看到下面的代码你肯定就明白了一 ...
- ios基础之 view的frame 与 bounds 的区别 (转)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- ios view的frame和bounds之区别(位置和大小)
前言: 学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bo ...
- 深入探究frame和bounds的区别以及setbounds使用
[转自]http://blog.csdn.net/hherima/article/details/39501857 在iOS开发中经常遇到两个词Frame和bounds,本文主要阐述Frame和bou ...
- iOS开发frame, contentSize, contentOffset, contentInset 区别联系浅析
1. 概述 iOS开发中,必然会涉及到布局相关问题,frame,bounds,contenSize,contentOffset,contentInset这几个布局相关概念让许多初学者感到困惑.虽然初步 ...
随机推荐
- c++中的array数组和vector数组
我觉得实验一下会记得比较牢,话不多直接上代码. 下面是array数组,感觉用的不多. //cpp 风格数组 array #include <iostream> #include <a ...
- AcceptEx与WSAEventSelect和Accept
(转自论坛的一个帖子http://bbs.csdn.net/topics/280032853) AcceptEx主要用于向完成端口 投递一个或多个的连接请求..当有连接时进来,这里分两种情况: 1.A ...
- jquery easyui-linkButton获取和设置按钮text并且解决火狐不支持innerText的方法
<a href="javascript:test" id="btn" class="easyui-linkbutton" iconCl ...
- lua安装和简单使用
1.安装 下载地址:https://www.lua.org/download.html 编译之前要安装readline,直接用yum安装 yum -y install readline-devel n ...
- 如何为C语言添加一个对象系统
为C语言添加OO能力的尝试从上世纪70年代到现在一直没有停止过,除了大获成的C++/Objective-C以外,还有很多其它的成功案例,比如GTK在libg中实现了一个对象系统,还有前几年一个OOC, ...
- 国内外从事CV相关的企业[转]
提示:本文为笔者原创,转载请注明出处:blog.csdn.net/carson2005 经常碰到朋友问我国内从事计算机视觉(CV)领域的公司的发展情况,产品情况,甚至找工作等问题,这里,我给出自己收集 ...
- 26.怎样在Swift中定义宏?
Swift 中没有宏定义,苹果建议使用let 或者 get 属性来替代宏定义值.虽然没有#define,但我们仍然可以使用 #if 并配合编译的配置来完成条件编译.下面会列出Swift项目开发中的一些 ...
- SCOM资源池
为了分散RMS特定的工作负载,默认创建有三个资源池. 1. All Management Servers Resource Pool: 将大多数RMS具体实例和工作流放入到这个池中.默认情况下,如果一 ...
- java学习路线(好资源大家分享)
对于入门java将近两年的时间,曾经迷惘过,一直想知道java的具体学习路线,看过了许许多多的java经验分享的帖子,评论,以及其他各种培训机构所谓的学习路线,发现没有一个符合我个人需求的学习路线,根 ...
- 什么是双线双IP,什么叫双线双IP
双线双IP实现双线路,拥有中国电信.中国网通骨干网的接入,在该机房托管的服务器,实现了电信和网通的双线路接入,使电信和网通的用户都能以非常快的速度连接到服务器,解决了电信和网通互相访问速度慢的问题.这 ...