IOS绘图
#import "ViewController.h"
#import "DrawView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)doTouchButton:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
DrawView *view=[[DrawView alloc]initWithFrame:self.view.frame];
view.backgroundColor =[UIColor whiteColor];
// [self.view addSubview:view];//去掉注释后,显示绘图
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)doTouchButton:(id)sender {
//小鸡走五角星
CGMutablePathRef startPath=CGPathCreateMutable();//创建一个路径
CGPathMoveToPoint(startPath, NULL, 160, 100);
CGPathAddLineToPoint(startPath, NULL, 220, 280);
CGPathAddLineToPoint(startPath, NULL, 60, 170);
CGPathAddLineToPoint(startPath, NULL, 260, 170);
CGPathAddLineToPoint(startPath, NULL, 100, 280);
CGPathAddLineToPoint(startPath, NULL, 160, 100);
CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration=5.0;//设置动画时间
[animation setPath:startPath];//设置路径
[_imageView.layer addAnimation:animation forKey:@"position"];
}
@end
/********************************************************/
//
// DrawView.h
// IOS绘图0817
//
// Created by 张艳锋 on 15/8/17.
// Copyright (c) 2015年 张艳锋. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface DrawView : UIView
@end
/********************************************************/
//
#import "DrawView.h"
@implementation DrawView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context=UIGraphicsGetCurrentContext();//绘制图形上下文
CGContextSetLineWidth(context, 2.0);//设直线条宽度
[[UIColor redColor]setStroke];//设置线条颜色
CGPoint point1=CGPointMake(160, 100);//上
CGPoint point2=CGPointMake(60, 170);//左
CGPoint point3=CGPointMake(260, 170);//右
CGPoint point4=CGPointMake(100, 280);//下左
CGPoint point5=CGPointMake(220, 280);//下右
CGContextMoveToPoint(context, point1.x, point1.y);
CGContextAddLineToPoint(context, point5.x, point5.y);
CGContextAddLineToPoint(context, point2.x, point2.y);
CGContextAddLineToPoint(context, point3.x, point3.y);
CGContextAddLineToPoint(context, point4.x, point4.y);
// CGContextAddLineToPoint(context, point1.x, point1.y);
CGContextClosePath(context);//闭合区域函数
// CGContextStrokePath(context);
[[UIColor orangeColor]setFill];//设置填充颜色
CGContextDrawPath(context, kCGPathFillStroke);//进行描绘函数
// kCGPathFill,//无边线,包围区域全部填充
// kCGPathEOFill,//无边线,包围区域重合部分不填充
// kCGPathStroke,//只显边线,不填充
// kCGPathFillStroke,//填充又显示边线
// kCGPathEOFillStroke//有边线包围区域重合部分不填充
//正方形
//CGContextAddRect矩形
//CGContextAddEllipseInRect椭圆 圆
CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);//红色
CGContextSetLineWidth(context, 1.5);
CGContextAddRect(context, CGRectMake(100, 60, 80, 80));//正方形
CGContextAddRect(context, CGRectMake(200, 60, 100, 200));//矩形
CGContextAddEllipseInRect(context,CGRectMake(50, 100, 100, 60));//椭圆
CGContextAddEllipseInRect(context,CGRectMake(50, 200, 100, 100));//圆
CGContextStrokePath(context);
}
IOS绘图的更多相关文章
- 论文第4章:iOS绘图平台的实现
面向移动设备的矢量绘图平台设计与实现 Design and Implementation of Mobile Device-oriented Vector Drawing Platform 引用本论文 ...
- iOS绘图教程 (转,拷贝以记录)
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,在翻译过程中我加入了一些书中没有涉及到的内容.希望本文能够对你有所帮助. 转自:http://www ...
- iOS绘图教程
本文是<Programming iOS5>中Drawing一章的翻译,考虑到主题完整性,翻译版本中加入了一些书中未涉及到的内容.希望本文能够对你有所帮助.(本文由海水的味道翻译整理,转载请 ...
- iOS绘图框架CoreGraphics分析
由于CoreGraphics框架有太多的API,对于初次接触或者对该框架不是十分了解的人,在绘图时,对API的选择会感到有些迷茫,甚至会觉得iOS的图形绘制有些繁琐.因此,本文主要介绍一下iOS的绘图 ...
- iOS绘图系统UIKit与Core Graphics
概述 iOS主要的绘图系统有UIKit,Core Graphics,Core Animation,Core Image,Open GL等,本片博文主要介绍UIKit与Core Graphics的绘图系 ...
- IOS 绘图教程Quartz2D
http://www.cocoachina.com/industry/20140115/7703.html http://www.cnblogs.com/wendingding/p/3803020.h ...
- ios绘图时的坐标处理
在iOS中,进行绘图操作时,一般主要是在UIView:drawRect中调用 UIGraphicsBeginImageContextWithOptions等一系列函数,有时候直接画图就行,比如UIIm ...
- iOS绘图UIBezierPath 和 Core Graphics框架
前言 iOS系统本身提供了两套绘图的框架,即UIBezierPath 和 Core Graphics.而前者所属UIKit,其实是对Core Graphics框架关于path的进一步封装,所以使用起来 ...
- iOS绘图—— UIBezierPath 和 Core Graphics
前言 iOS系统本身提供了两套绘图的框架,即UIBezierPath 和 Core Graphics.而前者所属UIKit,其实是对Core Graphics框架关于path的进一步封装,所以使用起来 ...
随机推荐
- Soft Renderer的乐趣
最近这一个月的闲暇时间在边学习<3D编程大师技巧>边做自己的Soft Renderer,一个月下来总算有了个“基本原型”的样子.主要是在编写图形管线的过程式代码,简单明了为第一个阶段的目标 ...
- JVM剖析
JVM剖析 这篇文章详细解释了Java虚拟机的内部架构.以下这幅图展示了Java虚拟机里面的关键组件(是依据Java SE 7版本的Java虚拟机). 这些组件将在下面的两个章节一一展开.第一章节涵盖 ...
- LINUX ping 指定网卡
计算机上有多块网卡(例如笔记本电脑的无线网卡和以太网卡)连接至网络,使用ping命令想指定使用哪块网卡怎么办? ping -I eth0 10.10.10.1ping -I eth1 10.10.10 ...
- 关于测试Windows电脑端口的命令 —— telnet用法
telnet服务在win7默认是打开的,如果没有打开要在电脑中打开. 命令格式:telnet ip port 例如:telnet 127.0.0.1 80 或者 telnet www.XXX.com ...
- FileSystemWatcher触发多次Change事件的解决办法 .
最近要用到FileSystemWatcher来监控某个目录中的文件是否发生改变,如果改变就执行相应的操作.但在开发过程中,发现FileSystemWatcher在文件创建或修改后,会触发多个Creat ...
- Aggressive cows 二分不仅仅是查找
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7083 Accepted: 3522 Description Farme ...
- Linux分区有损坏修复
如果Linux分区有损坏情况,启动有问题,不能正常进入文本或图形界面.那么一般会出现提示,需要输入Root密码登录后采用fsck -t ext3 -r /usr/local 修复 , /usr/loc ...
- [JavaEE] Eclipse中web-inf和meta-inf文件夹的信息
WEB-INF /WEB-INF/web.xml 你的Web应用程序配置文件,这是一个XML文件,其中描述了 servlet 和其他的应用组件配置及命名规则: /WEB- I ...
- Android小项目之十 应用程序更新的签名问题
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...
- Android小项目之七 应用程序的更新安装
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...