知识点 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. 如何在启用SharePoint浏览器功能的InfoPath 表单中添加托管代码以动态地加载并显示图片

    InfoPath 的浏览器表单不支持加载并显示图片,当然在模板中可以插入图片,但是如果想显示数据库的一幅图片,或是动态加载一张图片就无能为力了. 基实这个问题可以通过在浏览器表单中使用: " ...

  2. 设置UIImage的渲染模式:UIImage.renderingMode

    设置UIImage的渲染模式:UIImage.renderingMode 着色(Tint Color)是iOS7界面中的一个.设置UIImage的渲染模式:UIImage.renderingMode重 ...

  3. Android 第一个程序 及 环境搭配

    一. JDK配置 1.找到jdk安装路径 2.配置环境变量(建议配置在系统变量里面) 1).配置JAVA_HOME变量 2).配置 CLASSPATH 环境变量 CLASSPATH=.;%JAVA_H ...

  4. hybrid app

    hybrid app Hybrid App(混合模式移动应用)是指介于web-app.native-app这两者之间的app,兼具“Native App良好用户交互体验的优势”和“Web App跨平台 ...

  5. iOS---UISearchBar限制输入字数

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText // called when text ...

  6. request,session,application

    JSP 的3个内置对象request,session,application,其实都有一个作用域,这些对象内部有一个Map成员用于存放数据,比如session对象的setAttribute(key,v ...

  7. 弹出层在兼容模式和IE8模式下显示不正常

    弹出层在火狐.谷歌.360极速模式.IE6下都能100%面积正常显示,但在IE8和360的兼容模式下只显示弹出层下半部分或右半部分的内容,在主页面加上: <meta http-equiv=&qu ...

  8. 创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它

    package com.hanqi.test; public class sanjiaoxing { private double a; private double b; private doubl ...

  9. ASP.NET MVC 拓展ViewResult实现word文档下载

      最近项目中有同事用到word文档导出功能,遇到了一些导出失败问题,帮其看了下解决问题的同事,看了下之前的代码发现几个问题: 代码编写不规范,word导出功能未收口 重复代码导出都是 实现逻辑比较复 ...

  10. CentOS 7 网卡子接口的创建

    OS:CentOS 7 在linux上创建vlan需要加载802.1q模块: 1.检测OS是否已经加载802.1q模块 [root@controller ~]# modinfo 8021q filen ...