知识点 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 (一)的更多相关文章

  1. CGGeometry Reference

    CGRectUnionCGRectUnion接受两个CGRect结构体作为参数并且返回一个能够包含这两个矩形的最小矩形.听起来可能没什么,我相信你也可以用几行代码轻松实现这个功能,不过 CGGeome ...

  2. iOS 基础:Frames、Bounds 和 CGGeometry

    https://segmentfault.com/a/1190000004695617 原文:<iOS Fundamentals: Frames, Bounds, and CGGeometry& ...

  3. iOS编码规范

      The official raywenderlich.com Objective-C style guide.   This style guide outlines the coding con ...

  4. IOS开发-代码规范

    代码风格的重要性对于一个团队和项目来说不言而喻.网上有许多 Objective-C 的代码风格,但这份简洁而又最符合苹果的规范,同时有助于养成良好的代码习惯,也是我们团队一直遵循的代码风格. 写法没有 ...

  5. 官方的objective - c风格指南。

    The official raywenderlich.com Objective-C style guide. This style guide outlines the coding convent ...

  6. Objective-C 编码风格指南

    本文转自:[Objective-C 编码风格指南 | www.samirchen.com][2] ## 背景 保证自己的代码遵循团队统一的编码规范是一个码农的基本节操,能够进入一个有统一编码规范的团队 ...

  7. [转]IOS开发中的CGFloat、CGPoint、CGSize和CGRect

    http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGGeometry/Reference ...

  8. IOS开发中的CGFloat、CGPoint、CGSize和CGRect

    IOS开发中的CGFloat.CGPoint.CGSize和CGRect http://developer.apple.com/library/ios/#documentation/GraphicsI ...

  9. The official raywenderlich.com Objective-C style guide.

    The official raywenderlich.com Objective-C style guide. This style guide outlines the coding convent ...

随机推荐

  1. Fragment与FragmentActivity的关系

    前阵用viewpaper+fragment做滑动引导,查阅了下网上的资料,发现在有两种做法,一个是自建类直接继承Activity另一种是继承FragmentActivity,很是迷惑,在查了些goog ...

  2. Android 手机卫士--xutils说明与下载方法使用

    xUtils简介 xUtils 包含了很多实用的android工具. xUtils 最初源于Afinal框架,进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持(10种谓词) ...

  3. Android工程师常见面试题集答案

    13.描述一下Android的系统结构? android系统架构分从下往上为linux 内核层.运行库.应用程序框架层.和应用程序层. linuxkernel:负责硬件的驱动程序.网络.电源.系统安全 ...

  4. rabbitmq_management 安装失败

    安装rabbitmq_management的时候出现错误 不能连接rabbit,所以查看状态 看意思感觉好像是rabbit没有运行,但是安装的时候都是默认安装的,所以安装完以后服务的名字就是Rabbi ...

  5. 联通烽火hg220桥接tplink路由器

    转载请注明:from http://www.cnblogs.com/juandx/p/5544517.html 1.普通账户:user(7fnmmnml,默认是bdettbr0),猫背后可见 2.工程 ...

  6. PHP 5.3.0以上推荐使用mysqlnd驱动

    1. 什么是 mysqlnd 驱动 ? PHP 手册上的描述 : MySQL Native Driver is a replacement for the MySQL Client Library ( ...

  7. HDFS分布式文件系统资源管理器开发总结

      HDFS,全称Hadoop分布式文件系统,作为Hadoop生态技术圈底层的关键技术之一,被设计成适合运行在通用硬件上的分布式文件系统.它和现有的分布式文件系统有很多共同点,但同时,它和其他的分布式 ...

  8. Redis安装和配置

    1.下载安装redis 在linux服务器上,命令行执行以下命令(cd ./usr local/src 一般源码放在这里(推荐源码安装)) wget http://download.redis.io/ ...

  9. linux添加开机自启动脚本示例详解

    linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  10. monkeyrunner之环境搭建及实例(三)

    Monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器. 一.Monkeyrunner简介 1.MOnkeyrunner相对Mo ...