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 ...
随机推荐
- Vault插件示例--Vault Explorer与Thin Client的集成。
Autodesk Vault 2014的Subscription 包中有一个组件叫做Thin Client.这个瘦客户端有着全新的界面,又给了我们一个全新的选择.ThinClient实际是在Vault ...
- 【Leafletjs】6.Control.Loading推展-在地图上边框添加加载动态条
在已有的Control.Loading控件基础上结合CSS3 animation属性实现 .nz-loading .nz-loader { display: block; -webkit-animat ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q4-Q5)
Question 4 You are designing a SharePoint 2010 application to store 50 GB of digital assets, includi ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q63-Q65)
Question 63You are designing a SharePoint 2010 implementation that will be used by a company with a ...
- NSString方法与NSMutableString方法
NSString方法+(id) stringWithContentsOfFile:path encoding:enc error:err创建一个新字符串并将其设置为path指定的文件的内容,使用字符编 ...
- PHP中设置时区方法小结
找到原因后,在网上搜索到了一些关于PHP的时区设置方法: 1.修改php.ini,在php.ini中找到data.timezone =去掉它前面的;号,然后设置data.timezone = “Asi ...
- Extjs4.1中图片数据源
var jdPicStore = Ext.create('Ext.data.Store',{ fields: ['icon','evalValue'], ...
- EasyUi 改变 selelct 的 下拉内容 div 的高度
直接上 效果图: 修改之后的 滚动条高度: 代码: 源代码下载
- mysql 命令行操作入门(详细讲解版)
之前分享过多次Mysql主题,今天继续分享mysql命令行入门 1. 那么多mysql客户端工具,为何要分享命令行操作? -快捷.简单.方便 -在没有客户端的情况下怎么办 -如果是mysql未开启 ...
- 利用webview实现在andorid中嵌入swf
项目背景是这样的,一套系统有三个客户端分别是网页,flex和android,现在已经在flex上面做好了一个在线客户视频聊天系统,然后在这个基础上修改打包成了SWF,放在网页上面使用效果不错,但是利用 ...