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博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程 ...
随机推荐
- 数据结构 练习21-trie的原理分析和应用
前言 今天具体分析一下trie树,包括:原理分析,应用场合,复杂度分析,与hash的比较,源码展现.大部分内容来自互联网,文中会注明出处. 原理分析 主要是hash树的变种,先看下图: 每一个点存储一 ...
- PKU 2506 Tiling(递推+高精度||string应用)
题目大意:原题链接有2×1和2×2两种规格的地板,现要拼2×n的形状,共有多少种情况,首先要做这道题目要先对递推有一定的了解.解题思路:1.假设我们已经铺好了2×(n-1)的情形,则要铺到2×n则只能 ...
- web.xml中配置spring配置(application.xml)文件
application.xml 一般放到WEB-INF下,当然,你也可以将它放到任意问题,但需要web.xml指向到该文件 1.application.xml配置 <?xml version=& ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A Is it rated?
地址:http://codeforces.com/contest/807/problem/C 题目: C. Success Rate time limit per test 2 seconds mem ...
- ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)
题意:要在n天里给m个女生拍照,每个女生有拍照数量的下限Gi,每天有拍照数量的上限Di,每天当中每个人有拍照的上限Lij和Rij.求在满足限制的基础上,所有人最大能拍多少张照片. 分析:抛开限制,显然 ...
- webpack打包静态资源和动态资源
1.对于静态引用的资源: <img src = "static/modelname/imgname.png"> // 修改为下面的写法 <img src = &q ...
- Ubuntu16.04配置Android SDK环境
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html(注意32位与64位,我 ...
- Decker容器使用
Docker 客户端 我们可以直接输入 docker 命令来查看到 Docker 客户端的所有命令选项 root@ranxf:/home/ranxf# docker Usage: docker COM ...
- Oracle trunc()函数,decode()函数,substr函数,GREATEST函数,java中substring函数的用法
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...
- servlet的总结
tomcat在启动的时候 加载webapp下面的web.xml,加载里面定义的servlet. web.xml文件有两部分:servlet类定义和servlet映射定义每个被载入的servlet类都有 ...