CGPathCreateMutable
ios 图形与动画学习笔记 构造路径(CGPathCreateMutable)
一系列点放在一起,构成了一个形状。一系列的形状放在一起,构成了一个路径。
/*
路径属于我们正在绘制他们的上下文。路径没有边界(Boundary)或特定的形状,不想我们使用路径绘制出来的形状。
但路径没有边界框(Bounding boxes). 此处,Boundary与Bounding boxes完全不一样。
边界显示你在画布上哪些不可以用来绘画,而路径的边界框是包含了所有路径的形状、点和其他已经绘制的对象的最小矩形。
使用路径创建步骤:创建路径的方法返回一个路径的句柄,可以在绘制图形的使用就可以把句柄作为传递给core Graphics。
当创建路径之后,可以向它添加不同的点、线条和形状,之后绘制图形。
1、CGPathCreateMutable 函数
创建一个CGMutablePathRef 的可变路径,并返回其句柄。
2、CGPathMoveToPoint 过程
在路径上移动当前画笔的位置到一个点,这个点由CGPoint 类型的参数指定。
3、CGPathAddLineToPoint 过程
从当前的画笔位置向指定位置(同样由CGPoint类型的值指定)绘制线段
4、CGContextAddPath 过程
添加一个由句柄指定的路径的图形上下文,准备用于绘图
5、CGContextDrawPath 过程
在图形上下文中绘制给出的路径。
6、CGPathRelease 过程
释放为路径句柄分配的内存。
7、CGPathAddRect 过程
向路径添加一个矩形。矩形的边界由一个CGRect 结构体指定。
*/
/*
*创建一个新的可变路径(CGPathCreateMutable),把该路径加到你的图形上下文(CGContextAddPath)
*并把它绘制到图形上下文中(CGContextDrawPath)
*/
具体代码:
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
/*
*创建一个新的可变路径(CGPathCreateMutable),把该路径加到你的图形上下文(CGContextAddPath)
*并把它绘制到图形上下文中(CGContextDrawPath)
*/
/* Create the path */
CGMutablePathRef path = CGPathCreateMutable();
/* How big is our screen? We want the X to cover the whole screen */
CGRect screenBounds = [[UIScreen mainScreen] bounds];
/* Start from top-left */
CGPathMoveToPoint(path, NULL,screenBounds.origin.x, screenBounds.origin.y);
/* Draw a line from top-left to bottom-right of the screen */
CGPathAddLineToPoint(path, NULL,screenBounds.size.width, screenBounds.size.height);
/* Start another line from top-right */
CGPathMoveToPoint(path, NULL,screenBounds.size.width, screenBounds.origin.y);
/* Draw a line from top-right to bottom-left */
CGPathAddLineToPoint(path, NULL,screenBounds.origin.x, screenBounds.size.height);
/* Get the context that the path has to be drawn on */
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Add the path to the context so we can draw it later */
CGContextAddPath(currentContext, path);
/* Set the blue color as the stroke color */
[[UIColor blueColor] setStroke];
/* Draw the path with stroke color */
CGContextDrawPath(currentContext, kCGPathStroke);
/* Finally release the path object */
CGPathRelease(path);
/*
*传入CGPathMoveToPoint等过程的NULL参数代表一个既定的变换,在给定的路径绘制线条时可以使用此变换。
*/
}
转自:http://www.wahenzan.com/a/mdev/ios/2015/0130/1522.html
CGPathCreateMutable的更多相关文章
- iOS开发系列--打造自己的“美图秀秀”
--绘图与滤镜全面解析 概述 在iOS中可以很容易的开发出绚丽的界面效果,一方面得益于成功系统的设计,另一方面得益于它强大的开发框架.今天我们将围绕iOS中两大图形.图像绘图框架进行介绍:Quartz ...
- iOS之绘制虚线
/* ** lineFrame: 虚线的 frame ** length: 虚线中短线的宽度 ** spacing: 虚线中短线之间的间距 ** co ...
- iOS绘制收益柱状图
项目需求,参考了其他绘图demo,自己绘制出来了,不过代码改得有点乱,添加了很多变量,时间关系没用太合适的命名,逻辑处理也没进行优化. 看看效果图(虚线区域都是画的,其他区域添加的都是控件),附上源码 ...
- Quartz2D内存管理
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #239619 } p.p2 ...
- 4.1/4.2 多线程进阶篇<上>(Pthread & NSThread)
本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书” 本文源码 Demo 详见 Githubhttps://github.com/shorfng ...
- iOS CoreAnimation详解(一) 有关Layer的动画
以前由于项目需要 也写了一些动画 ,但是知识不系统,很散.这段时间趁着项目完成的空袭,来跟着大神的脚步系统的总结一下iOS中Core Animation的知识点. 原博客地址:http://blog. ...
- iOS CALayer应用详解(2)
参考博客:http://blog.csdn.net/hello_hwc?viewmode=list 如果你对CALayer 还没有一个清晰的理解,欢迎看一下前面的博客: http://www.cnbl ...
- iOS CALayer应用详解
跟着大神一起进步,本篇博客原文地址:http://blog.csdn.net/hello_hwc?viewmode=contents 一 CALayer是什么? Layers是绘图和动画的基础, L ...
- iOS开发小技巧 -- tableView-section圆角边框解决方案
[iOS开发]tableView-section圆角边框解决方案 tableView圆角边框解决方案 iOS 7之前,图下圆角边框很容易设置 iOS 7之后,tableviewcell的风格不再是圆角 ...
随机推荐
- C#中使用SQLite数据库简介(下)
[SQLite管理工具简介] 推荐以下2款: Navicat for SQLite:功能非常强大,几乎包含了数据库管理工具的所有必需功能,操作简单,容易上手.唯一的缺点是不能打开由System.Dat ...
- hadoop中InputFormat 接口的设计与实现
InputFormat 主要用于描述输入数据的格式, 它提供以下两个功能.❑数据切分:按照某个策略将输入数据切分成若干个 split, 以便确定 Map Task 个数以及对应的 split.❑为 M ...
- 关于angularjs中路由页面强制更新的问题
有这么一个问题,在页面内路由页面跳转时,第一次跳入路由页面时是正常的,但是第二次会记住第一次时的状态,有时候并不想这样,想强制更新这个路由页面. 有一种方式就是使用 ui-sref-opts功能,我试 ...
- a标签添加点击事件
a标签添加点击事件 CreateTime--2017年8月8日09:11:34 Author:Marydon 一.基础用法 方式一:(不推荐使用) <a href="javascr ...
- 解析_theme_build_registry()和_theme_process_registry()
Drupal使用_theme_build_registry()和_theme_process_registry()两个函数构建theme registry.theme registry是theme h ...
- 腾讯QQ的历史
http://www.agenow.com/bbs/DispText.aspx?id=1385106 OICQ: 大家都习惯性的认为OICQ是马化腾先生自己动手研发的,可在腾讯内部的网友之间又传来 ...
- Android屏幕计量单位详解
1.px (pixels)(像素):是屏幕的物理像素点,与密度相关,密度大了,单位面积上的px会比较多.通常不推荐使用这个. 2.dip或dp(与密度无关的像素):一个基于density的抽象单位,这 ...
- C#:设置控件样式(待补充)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- 在一个SQL Server表中一行的多个列找出最大值
有时候我们需要从多个相同的列里(这些列的数据类型相同)找出最大的那个值,并显示 这里给出一个例子 IF (OBJECT_ID('tempdb..##TestTable') IS NOT NULL) D ...
- js 根据title从下级往上级查找
var menuData = [{ name: 'manage', title: '测试1', icon: 'home', }, { title: '测试2', name: 'car-parent', ...