IOS-涂鸦
//
// PaintView.m
// IOS_0224_涂鸦
//
// Created by ma c on 16/2/24.
// Copyright © 2016年 博文科技. All rights reserved.
// #import "PaintView.h" @interface PaintView () //存放每次触摸的完整路径
@property (nonatomic, strong) NSMutableArray *path; @end @implementation PaintView - (NSMutableArray *)path
{
if (_path == nil) {
_path = [NSMutableArray array];
}
return _path;
} /*方法一*/
/*
//确定起点
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint startPoint = [touch locationInView:touch.view]; //每次开始触摸,就新建一个数组来存放这次触摸的所有点
NSMutableArray *pathPoints = [NSMutableArray array];
[pathPoints addObject:[NSValue valueWithCGPoint:startPoint]];
//添加每次触摸的所有点形成的路径到path中
[self.path addObject:pathPoints]; [self setNeedsDisplay];
}
//连线
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:touch.view]; //取出这次路径对应的数组
NSMutableArray *pathPoints = [self.path lastObject];
[pathPoints addObject:[NSValue valueWithCGPoint:currentPoint]]; [self setNeedsDisplay]; }
//结束点
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint endPoint = [touch locationInView:touch.view]; //取出这次路径对应的数组
NSMutableArray *pathPoints = [self.path lastObject];
[pathPoints addObject:[NSValue valueWithCGPoint:endPoint]]; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext(); for (NSMutableArray *points in self.path) {
for (int i = 0; i < points.count; i++) { //一条路径 CGPoint point = [points[i] CGPointValue]; if (i == 0) {
CGContextMoveToPoint(ctx, point.x, point.y);
}else{
CGContextAddLineToPoint(ctx, point.x, point.y);
}
}
} CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextSetLineWidth(ctx, 5);
CGContextStrokePath(ctx);
} */ /*方法二*/
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//1.获得当前触摸点
UITouch *touch = [touches anyObject];
CGPoint startPoint = [touch locationInView:touch.view];
//2.创建一个新的路径
UIBezierPath *startPath = [UIBezierPath bezierPath]; startPath.lineWidth = ;
startPath.lineCapStyle = kCGLineCapRound;
startPath.lineJoinStyle = kCGLineJoinRound;
//设置起点
[startPath moveToPoint:startPoint];
//3.添加路径到数组中
[self.path addObject:startPath]; [self setNeedsDisplay]; } - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:touch.view]; UIBezierPath *currentPath = [self.path lastObject];
[currentPath addLineToPoint:currentPoint]; [self setNeedsDisplay];
} - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event]; } - (void)drawRect:(CGRect)rect
{
[[UIColor redColor] set];
for (UIBezierPath *path in self.path) {
[path stroke];
}
} - (void)clear
{
[self.path removeAllObjects];
[self setNeedsDisplay];
} - (void)back
{
[self.path removeLastObject];
[self setNeedsDisplay];
} @end
IOS-涂鸦的更多相关文章
- iOS开发——高级篇——iOS涂鸦画板效果实现
一个简单的绘图应用,模仿苹果自带软件备忘录里的涂鸦功能 核心代码 #import "DrawView.h" #import "DrawPath.h" @inte ...
- iOS涂色涂鸦效果、Swift仿喜马拉雅FM、抽屉转场动画、拖拽头像、标签选择器等源码
iOS精选源码 LeeTagView 标签选择控件 为您的用户显示界面添加美观的加载视图 Swift4: 可拖动头像,增加物理属性 Swift版抽屉效果,自定义转场动画管理器 Swift 仿写喜马拉雅 ...
- iOS自定义弹出视图、收音机APP、图片涂鸦、加载刷新、文件缓存等源码
iOS精选源码 一款优秀的 聆听夜空FM 源码 zhPopupController 简单快捷弹出自定义视图 WHStoryMaker搭建美图(贴纸,涂鸦,文字,滤镜) iOS cell高度自适应 有加 ...
- iOS实现白板、画板功能,有趣的涂鸦工具,已封装,简单快捷使用
一.效果图: 二.选择颜色: 分[固定颜色模式]和[自由取模式]. 三.操作栏功能: 1.撤销:撤销上一步操作,可一直往上进行,直到全部清空. 2.清空:直接清除所有绘画. 3.橡皮擦:去除不要的绘 ...
- iOS 高级去水印,涂鸦去水印
目前在研究一下图像的处理,看了一下相关的软件,比如:<去水印大师>,究竟去水印是怎么处理的呢?看图分析. 一共是三个功能:快速去水印.高级去水印.涂鸦去水印 快速去水印:暂时没找到好的处理 ...
- iOS:quartz2D绘图小项目(涂鸦画板)
介绍:学了quartz2D的绘图知识后,我根据它的一些功能制作了一个小项目:涂鸦画板. 功能:绘制各种图形,还可以选取相册上的照片做涂鸦,然后保存到相册中.其中,还包括功能有:颜色的选取.线宽的选取. ...
- [iOS UI进阶 - 4.0] 涂鸦app Demo
A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D code source: https://github.com/hellovoidwor ...
- iOS开发Quartz2D 十三:画板涂鸦
一:效果如图: 二:代码 #import "ViewController.h" #import "DrawView.h" #import "Handl ...
- iOS 10 新特性 大汇总 及iOS 10 的一些小问题和 xcode 8 的新版本小问题
iOS 10正式版是很值得升级的,特别是那些不打算购买iPhone 7的老用户,毕竟新系统在体验.流畅性上都做了一些升级. 1.开放电话接口 支持垃圾电话提醒 对于使用iPhone的国人来说,这个功能 ...
- 文顶顶iOS开发博客链接整理及部分项目源代码下载
文顶顶iOS开发博客链接整理及部分项目源代码下载 网上的iOS开发的教程很多,但是像cnblogs博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程 ...
随机推荐
- 磁盘结构,平均寻道时间,平均延迟时间,虚拟内存与MMU
首先了解一下磁盘:磁盘低速的原因是因为它一种机械装置,在磁盘中有一个或多个金属盘片,它们以5400,7200或10800rpm(RPM =revolutions per minute 每分钟多少转 ) ...
- 网页采集利器 phpQuery
网页采集利器 phpQuery 2012-02-28 11:43:24| 分类: php|举报|字号 订阅 在网页采集的时候,通常都会用到正则表达式.但是有时候对于正则不太好的同学,比如我, ...
- The Cheap KD 10 is my best shoe yet
10 years of anything is fairly huge Cheap KD 10, but adding something as great as Flyknit causes it ...
- DevStore教你如何玩转饥饿营销?
首先我们必需知道: 所谓“饥饿营销”,是指商品提供者有意调低产量,以期达到调控供求关系.制造供不应求“假象”.维持商品较高售价和利润率的目的. 饥饿营销”营销方式,其通常的步骤: 1.引起关注.首先是 ...
- HDU - 4786 Fibonacci Tree (MST)
题意:给一张由白边和黑边构成的无向图,求是否存在一个生成树,使白边的数量为一个斐波那契数. 分析:白边权值为1,黑边权值为0.求出该图的最小生成树和最大生成树,若这两个值之间存在斐波那契数,则可以,若 ...
- Windows和Ubuntu双系统
1 重装系统:Windows(Win7) 1.1 下载大白菜/老毛桃等工具,把U盘制作成启动盘 1.2 下载windows系统镜像文件放入U盘中 1.3 U盘插入待装系统的主机,开机进入BIOS( ...
- Twitter的分布式自增ID算法snowflake
snowflake 分布式场景下获取自增id git:https://github.com/twitter/snowflake 解读: http://www.cnblogs.com/relucent/ ...
- selenium+xpath 文本信息定位
selenium中根据父子.兄弟.相邻节点定位的方法,很多人在实际应用中会遇到想定位的节点无法直接定位,需要通过附近节点来相对定位的问题,但从父节点定位子节点容易,从子节点定位父节点.定位一个节点的哥 ...
- MVC 中 注册不成功 或其他操作不成功 提示办法
在Controller中 .cs public ActionResult AddUser(User u) { …… try { …… GetInsertUser(u); // 注册 ...
- Mac系统安装MyEclipse
参考链接 http://blog.csdn.net/jin_kwok/article/details/51925523