Iphone画笔功能
iphone灵敏的触摸功能在应用开发中有很多的用处,你可以用它来开发一个手绘软件。在此我将探讨一下iphone手绘功能的实现, 很简单,创建一个base-view的工程, 然后所有的工作都是在触摸事件中, 实现touchesBegan, touchesMoved, touchesEnded三个方法。
在屏上移动就能实现手绘,点击画个点,双击清空绘制。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = NO; UITouch *touch = [touches anyObject]; if ([touch tapCount] == 2) { drawImage.image = nil; return; } lastPoint = [touch locationInView:self.view]; lastPoint.y -= 20; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; currentPoint.y -= 20; UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); lastPoint = currentPoint; mouseMoved++; if (mouseMoved == 10) { mouseMoved = 0; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch tapCount] == 2) { drawImage.image = nil; return; } if(!mouseSwiped) { UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); CGContextFlush(UIGraphicsGetCurrentContext()); drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } }
参考:http://www.ipodtouchfans.com/forums/showthread.php?t=132024
里面有源码下载。
Iphone画笔功能相关推荐
- iphone录屏没内部声音_6个iPhone隐藏功能,让你的手机好用到飞起
很多小伙伴一直用iPhone,但其实并没有深入了解它,有些隐藏功能和小技巧甚至果粉都不一定知道. 今天小趣找到几个iPhone实用又好玩的隐藏功能,简直就像打开新世界大门的感觉,这就分享给大家! 1. ...
- 【Scratch】青少年蓝桥杯_每日一题_11.01_画笔功能
用心写好每一篇文章 效果图 一.题目背景 通过编程实现具有画笔功能的程序﹐按下鼠标画笔跟随鼠标移动﹐抬起鼠标画笔停止绘制. 二.编程实现 1)运行程序,清空屏幕﹐画笔角色隐藏; 2)在舞台区域按下鼠标 ...
- iPhone卫星功能仅用于紧急通信;韩国通过立法禁止苹果、谷歌垄断支付系统;Linux 5.14 版本发布|极客头条
一分钟速览新闻点! 小米集团加入开源专利社区 OIN 饿了么:延长扬州会员一个月的权益 阿里云教育推出钉钉课后服务系统 华为 P50 Pro 推送鸿蒙更新 淘宝更换新的 Slogan 为"淘 ...
- MFC 画笔功能实现
一.4个消息处理 如果是在VS2012上,我们可以很方便的在对话框的属性栏找到消息页面添加消息 如果是以前的VC6的版本,那还是得老老实实使用Class Wizzard类向导添加消息 左键按下.抬起. ...
- ar测量距离android,精度惊人!使用iPhone AR功能测量距离
原标题:精度惊人!使用iPhone AR功能测量距离 很有可能的是,苹果iPhone的下一个重大创新将是在AR增强现实方面,苹果经常被吐槽"发明"了其他人已经做了多年的东西,但苹果 ...
- iPhone不为人知的功能常用技巧,看完后才发现很多用iPhone的人实在是愧对乔布斯! - imsoft.cnblogs...
很多人花了四五千买部苹果,结果只用到四五百块钱的普通手机功能. iPhone不为人知的功能,常用技巧: 网上搜集整理的iPhone快捷键操作,虽然表面上iPhone按键只有一个HOME键,大部分操作都 ...
- 苹果计算机的隐藏功能有哪些,iPhone隐藏功能有哪些
今天凌晨,苹果官方发布iOS 10.3最后一个测试版本.预计月底将推出iOS 10.3正式版.在新版本到来之前,你是否已经掌握了iPhone所有功能,下面给大家准备一些干货,简单介绍一些iPhone隐 ...
- 苹果降频门:旧款iPhone哪些功能受到影响
要说苹果最近发生的大事,就数网络上传的沸沸扬扬的降频门事件了,近期苹果在新发布的iOS 11系统中新增了一项功能,意在降低旧款手机的电量消耗,但限制了旧款iPhone的性能,那么iPhone有哪些功能 ...
- swift 滑动 iphone解锁_这10个iPhone隐藏功能,我就不信你全知道
Hi,大家好,我是爱倒腾电子产品的祈雨. 从安卓阵营转到苹果已经快一年了,我从最初的束手束脚,到现在的乐得清闲,已经逐渐适应了苹果的这套系统. 总的来说,安卓就像去吃自助餐: 满眼的食物任你挑选,最后 ...
最新文章
- 深度学习先驱Bengio:AI顶会论文的Deadline是时候取消了
- 皮一皮:这剧透的太厉害了...
- 【Android 逆向】Android 权限 ( ro.product.cpu.abi 属性 | ro.zygote 属性 | dhcp.eth0 属性 | net.* 属性 )
- 2D平台游戏王牌英雄的AI寻路解决方案
- 梯度下降法Gradient Descent深度学习 机器学习
- 跟小段一起学Solaris(20)---ipFilter防火墙
- 源码解析:Git的第一个提交是什么样的?
- python中用于循环结构的关键字_详解Python的循环结构知识点
- 非GUI运行性能脚本
- 新版标准日本语初级_第二课
- dlib实现人脸对齐方法
- 【总结】仰望星空,脚踏实地 2017.09-2018.02
- dbt(data build tool) is an open source data transformation, and using Jinji templating
- 高维空间中的体积(包含递归思想的初步理解)
- 存储系统基础知识介绍
- 阿里云服务器与腾讯云服务器的故事
- LaTex 数学之矩阵
- 雷军:从苦逼撸代码到年入上百亿,成为商界领袖,改变现状,只靠单纯写代码远远不够
- 在信用证支付的情况下,空运单可否作成以银行为收货人?在此种情况下可否起到约束进口方付款的作用?...
- 个人自我介绍PPT模板推荐