//
// 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-涂鸦的更多相关文章

  1. iOS开发——高级篇——iOS涂鸦画板效果实现

    一个简单的绘图应用,模仿苹果自带软件备忘录里的涂鸦功能 核心代码 #import "DrawView.h" #import "DrawPath.h" @inte ...

  2. iOS涂色涂鸦效果、Swift仿喜马拉雅FM、抽屉转场动画、拖拽头像、标签选择器等源码

    iOS精选源码 LeeTagView 标签选择控件 为您的用户显示界面添加美观的加载视图 Swift4: 可拖动头像,增加物理属性 Swift版抽屉效果,自定义转场动画管理器 Swift 仿写喜马拉雅 ...

  3. iOS自定义弹出视图、收音机APP、图片涂鸦、加载刷新、文件缓存等源码

    iOS精选源码 一款优秀的 聆听夜空FM 源码 zhPopupController 简单快捷弹出自定义视图 WHStoryMaker搭建美图(贴纸,涂鸦,文字,滤镜) iOS cell高度自适应 有加 ...

  4. iOS实现白板、画板功能,有趣的涂鸦工具,已封装,简单快捷使用

    一.效果图: 二.选择颜色: 分[固定颜色模式]和[自由取模式].  三.操作栏功能: 1.撤销:撤销上一步操作,可一直往上进行,直到全部清空. 2.清空:直接清除所有绘画. 3.橡皮擦:去除不要的绘 ...

  5. iOS 高级去水印,涂鸦去水印

    目前在研究一下图像的处理,看了一下相关的软件,比如:<去水印大师>,究竟去水印是怎么处理的呢?看图分析. 一共是三个功能:快速去水印.高级去水印.涂鸦去水印 快速去水印:暂时没找到好的处理 ...

  6. iOS:quartz2D绘图小项目(涂鸦画板)

    介绍:学了quartz2D的绘图知识后,我根据它的一些功能制作了一个小项目:涂鸦画板. 功能:绘制各种图形,还可以选取相册上的照片做涂鸦,然后保存到相册中.其中,还包括功能有:颜色的选取.线宽的选取. ...

  7. [iOS UI进阶 - 4.0] 涂鸦app Demo

    A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D   code source: https://github.com/hellovoidwor ...

  8. iOS开发Quartz2D 十三:画板涂鸦

    一:效果如图: 二:代码 #import "ViewController.h" #import "DrawView.h" #import "Handl ...

  9. iOS 10 新特性 大汇总 及iOS 10 的一些小问题和 xcode 8 的新版本小问题

    iOS 10正式版是很值得升级的,特别是那些不打算购买iPhone 7的老用户,毕竟新系统在体验.流畅性上都做了一些升级. 1.开放电话接口 支持垃圾电话提醒 对于使用iPhone的国人来说,这个功能 ...

  10. 文顶顶iOS开发博客链接整理及部分项目源代码下载

    文顶顶iOS开发博客链接整理及部分项目源代码下载   网上的iOS开发的教程很多,但是像cnblogs博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程 ...

随机推荐

  1. 编写项目readme文件

    1.使用markdown 编写项目说明,markdown 编辑器推荐使用 小书匠 2.在当前项目根目录下使用cmd中的tree 命令 生成项目结构文件到指定的txt文件中,具体命令为:tree d: ...

  2. docker——安装

    Docker划分为CE和EE.CE即社区版(免费,支持后期三个月),EE即企业版,强调安全,付费使用. #安装依赖包 yum install -y yum-utils device-mapper-pe ...

  3. wget 用法

    wget -r -p -np -k http://xxx.com/xxx

  4. Linux系统——引导过程与服务控制

    一.Linux开机启动原理(十步) (1)开机自检BIOS 开机检测,主板检测 (2)MBR引导 硬盘512字节 (3)GRUB菜单 操作系统菜单 (4)加载内核(kernel) 启动操作系统核心,根 ...

  5. 怎么创建Porlet项目

    首先找到你liferay安装的地址D:\liferay\liferay-bundles-6.1.1\plugins-sdk,找到portlets这个文件夹点击(shift+鼠标右键)进入命令行窗口,写 ...

  6. vue生命周期探究(二)

    vue生命周期探究(二) 转载自:https://segmentfault.com/a/1190000008923105 上一章我们介绍了vue的组件生命周期和路由勾子,这一章,让我们来看看在vue- ...

  7. JMeter5.0 边界提取器使用

    需求: 需要提取下图中requestNo的值,使用JMeter3.1和4.0版本,使用正则表达式提取器始终无法获取 而后使用JMeter5.0的边界提取器,不需要写复杂的正则表达式,只要填写左右边界即 ...

  8. TortoiseSVN_1.9.1.267_x64版本控制系统(针对Visual SVN Server)使用简单介绍

    软件下载地址:TortoiseSVN(SVN客户端)64位 V1.9.1.267简体中文免费版 软件详细操作说明:TortoiseSVN使用说明书(超详细) 文章内容:此篇是简单记录如何从Visual ...

  9. Linux下安装SVN服务端

    安装 使用yum安装非常简单: yum install subversion 配置 2.1. 创建仓库 我们这里在/home下建立一个名为svn的仓库(repository),以后所有代码都放在这个下 ...

  10. swoole 异步队列简明教程

    安装步骤如下(推荐把安装文件下载到 /usr/local/src 目录下): step 1: wget --no-check-certificate https://github.com/swoole ...