CGGeometry Reference (一)
知识点 frame 与bounds 的区别
1.frame 是这个视图的大小在父视图的位置 。 如x 20 y 20 width 200 height 300
2.bounds 是这个视图的大小在自身的位置 。 如 x 0 y 0 width 200 height 300 ,bounds 的x,y 永远为0.
3.CGRectUnion 接受两个CGRect 结构体作为参数并且返回一个能够包含这两个矩形的最小矩形,听起来可能没什么,我相信你也可以用几行代码轻松实现这个功能,不过 CGGeometry 做的是给你提供一些方法让你的代码更干净、可读性更强。
// CGRectUnion
CGRect frame1 = CGRectMake(80.0, 100.0, 150.0, 240.0);
CGRect frame2 = CGRectMake(140.0, 240.0, 120.0, 120.0);
CGRect frame3 = CGRectUnion(frame1, frame2);
UIView *view1 = [[UIView alloc] initWithFrame:frame1];
[view1 setBackgroundColor:[UIColor redColor]];
UIView *view2 = [[UIView alloc] initWithFrame:frame2];
[view2 setBackgroundColor:[UIColor orangeColor]];
UIView *view3 = [[UIView alloc] initWithFrame:frame3];
[view3 setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:view3];
[self.view addSubview:view2];
[self.view addSubview:view1];
4.CGRectDivide 它帮你把一个给定矩形分割成两个
// CGRectDivide
CGRect frame = CGRectMake(10.0, 50.0, 300.0, 300.0);
CGRect part1;
CGRect part2;
CGRectDivide(frame, &part1, &part2, 100.0, CGRectMaxYEdge);
UIView *view1 = [[UIView alloc] initWithFrame:frame];
[view1 setBackgroundColor:[UIColor grayColor]];
UIView *view2 = [[UIView alloc] initWithFrame:part1];
[view2 setBackgroundColor:[UIColor orangeColor]];
UIView *view3 = [[UIView alloc] initWithFrame:part2];
[view3 setBackgroundColor:[UIColor redColor]];
[self.view addSubview:view1];
[self.view addSubview:view2];
[self.view addSubview:view3];
比较和包含
用下面六个方法来比较几何结构和检查包含关系非常简单。
- CGPointEqualToPoint
- CGSizeEqualToSize
- CGRectEqualToRect
- CGRectIntersectsRect
- CGRectContainsPoint
- CGRectContainsRect
CGGeometry Reference 还有一些其他宝贝,比如CGPointCreateDictionaryRepresentation可以用来将一个 CGPoint 结构体转换为一个 CGDictionaryRef,CGRectIsEmpty可以用来检查一个矩形的宽高是否都为零。更多详情请看[《CGGeometry Reference 文档》]()。
CGGeometry Reference (一)的更多相关文章
- CGGeometry Reference
CGRectUnionCGRectUnion接受两个CGRect结构体作为参数并且返回一个能够包含这两个矩形的最小矩形.听起来可能没什么,我相信你也可以用几行代码轻松实现这个功能,不过 CGGeome ...
- iOS 基础:Frames、Bounds 和 CGGeometry
https://segmentfault.com/a/1190000004695617 原文:<iOS Fundamentals: Frames, Bounds, and CGGeometry& ...
- iOS编码规范
The official raywenderlich.com Objective-C style guide. This style guide outlines the coding con ...
- IOS开发-代码规范
代码风格的重要性对于一个团队和项目来说不言而喻.网上有许多 Objective-C 的代码风格,但这份简洁而又最符合苹果的规范,同时有助于养成良好的代码习惯,也是我们团队一直遵循的代码风格. 写法没有 ...
- 官方的objective - c风格指南。
The official raywenderlich.com Objective-C style guide. This style guide outlines the coding convent ...
- Objective-C 编码风格指南
本文转自:[Objective-C 编码风格指南 | www.samirchen.com][2] ## 背景 保证自己的代码遵循团队统一的编码规范是一个码农的基本节操,能够进入一个有统一编码规范的团队 ...
- [转]IOS开发中的CGFloat、CGPoint、CGSize和CGRect
http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGGeometry/Reference ...
- IOS开发中的CGFloat、CGPoint、CGSize和CGRect
IOS开发中的CGFloat.CGPoint.CGSize和CGRect http://developer.apple.com/library/ios/#documentation/GraphicsI ...
- The official raywenderlich.com Objective-C style guide.
The official raywenderlich.com Objective-C style guide. This style guide outlines the coding convent ...
随机推荐
- CATransform3D方法汇总
CATransform3D三维变换 struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGF ...
- 安卓开发基础之tween动画基本使用,代码教学
xml代码块: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:andro ...
- OC self = [super init] , 点语法 , @property
OC self = [super init] , 点语法 , @property 构造方法为啥这么写? self = [super init]; [super init] 的结果可能有三种: 第一种: ...
- cocoapods遇到的问题 (pod: command not found的问题)
在使用CocoaPod为项目添加第三方类库时,出现了-bash: pod: command not found的问题: 在网上看到了一位哥的方法:确实有效:
- Sql server profiler抓出的语句不可信
Sql profiler抓出的语句不可信
- MySQL两种表存储结构MyISAM和InnoDB的性能比较测试
转载 http://www.jb51.net/article/5620.htm MySQL支持的两种主要表存储格式MyISAM,InnoDB,上个月做个项目时,先使用了InnoDB,结果速度特别慢,1 ...
- Mac OS X 删除文件快捷键
今天发现自己还不知道怎么快捷的删除文件,网上找了下相关的资料. 原来删除文件的快捷键是:command+delete(把文件放到废纸篓),对于我这种笔记本用户,确实方便很多哈 还有一个命令也挺有用的: ...
- 安卓开发第一步:Android Studio安装配置
虽然本人是JAVA开发工程师平时主要开发Web App,但因为项目需求需要开发对应的移动端.一时又找不到合适的安卓开发人员,兄弟我只好被项目经理"抓来当壮丁了".俗话说好" ...
- SSH加载顺序问题
http://bbs.csdn.net/topics/390299835 个人总结 1.项目启动首先加载WEB.xml文件 wen.xml文件中有 <!-- tomcat默认生成的地方是 ...
- EasyUi 改变 selelct 的 下拉内容 div 的高度
直接上 效果图: 修改之后的 滚动条高度: 代码: 源代码下载