//
// 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. mysql锁机制之乐观锁(二)

    select for update: 在执行这个 select 查询语句的时候,会将对应的索引访问条目进行上排他锁(X 锁),也就是说这个语句对应的锁就相当于update带来的效果. select * ...

  2. 【Linux学习】1.Linux基础知识

    记录学习Linux 系统的相关知识点,欢迎大家拍砖交流,一起成长:QQ:2712192471 作者背景:前端开发工程师 | Python | web安全爱好者 一,Windows系统下 Linux 的 ...

  3. JS正则表达式从入门到入土(8)—— REGEXP对象属性

    对象属性 常用对象属性主要有以下几种: 1.global: 是否全文搜索,默认false 2.ignore case:是否大小写敏感,默认是false 3.multiline:多行搜索,默认值是fal ...

  4. GridView自定义自增长的 序号 列

    如图所示,添加一个普通列(非模板列),将其显示文本为    序号 在GridView的RowDataBound事件中作如下处理 后台.CS 代码:

  5. Linux简单编程学习心得

    在Linux环境下简单编程学习心得 linux编程过程 在上周的<信息安全设计基础>的课程学习中学习到了在虚拟的linux环境下简单的编程.学习过程中接触到了vim.gcc和gcd在实验楼 ...

  6. 20135320赵瀚青LINUX内核分析第三周学习笔记

    赵瀚青原创作品转载请注明出处<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 概述 本周是学习的主要是构造 ...

  7. C语言string.h常用函数总结

    void *memcpy(void *dest, const void *src, size_t n); 从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中. ...

  8. Jquery2 基础核心

    学习要点: 1.代码风格 2.加载模式 3.对象互换 4.多个库之间的冲突 本节简单的介绍一下jQuery 一些核心的问题. 一.代码风格 在jQuery程序中,不管是页面元素的选择.内置的功能函数, ...

  9. django中的分页设置

    1.在控制台中的展示 from django.core.paginator import Paginator iter = 'abcdefghijklmn' inator = Paginator(it ...

  10. du df 磁盘命令

    du命令是检查硬盘使用情况,统计文件或目录及子目录使用硬盘的空间大小.参数的不同组合,可以更快的提高工作效率,以下仅列出了经常使用到的参数,如需更详细的信息,请用man du命令来获得.   说明 - ...