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博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程 ...
随机推荐
- Vim 我用的python相关插件
1. pydoc.vim(https://github.com/vim-scripts/pydoc.vim) 查找python文档. 使用方法: :Pydoc <keyword> ...
- HashMap底层原理
原文出自:http://zhangshixi.iteye.com/blog/672697 1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射 ...
- POJ - 2699 The Maximum Number of Strong Kings (最大流+枚举)
题意:有n(n<=10)个选手,两两之间打比赛,共有n*(n-1)/2场比赛,赢一场得1分.给出每个人最后的得分.求有多少个定义如下的strong king:赢了所有得分比自己高的人或本身就是分 ...
- ISAP模板
#include<bits/stdc++.h> using namespace std; using namespace std; typedef long long ll; const ...
- [转]美国最大婚恋交友网站eHarmony的机器学习实践
转自:http://www.csdn.net/article/2015-03-19/2824267 上周,我去洛杉矶参加了一个机器学习的meetup,一位主讲是eHarmony公司(美国最大的婚恋交友 ...
- 三张图看遍Linux性能监控、测试、优化工具
Linux 平台上的性能工具有很多,眼花缭乱,长期的摸索和经验发现最好用的还是那些久经考验的.简单的小工具.系统性能专家 Brendan D. Gregg在最近的 LinuxCon NA 2014 大 ...
- C#如何获取枚举(Enum)变量的值
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Enum ...
- c++对txt文件的读取与写入
转自:http://blog.csdn.net/lh3325251325/article/details/4761575 #include <iostream> #include < ...
- 超级强大的vim配置(vimplus)--续集
An automatic configuration program for vim 安装(github地址:https://github.com/chxuan/vimplus.git, 欢迎star ...
- xshell ssh 上传文件
一.通过xshell ssh 上传文件 [lxk@localhost ~]$ yum install lrzsz 安装 [lxk@localhost ~]$ rz 上传文件