Iphone画笔功能
2010-10-28 21:49
155 查看
iphone灵敏的触摸功能在应用开发中有很多的用处,你可以用它来开发一个手绘软件。在此我将探讨一下iphone手绘功能的实现, 很简单,创建一个base-view的工程, 然后所有的工作都是在触摸事件中, 实现touchesBegan, touchesMoved, touchesEnded三个方法。
在屏上移动就能实现手绘,点击画个点,双击清空绘制。
参考:http://www.ipodtouchfans.com/forums/showthread.php?t=132024
里面有源码下载。
在屏上移动就能实现手绘,点击画个点,双击清空绘制。
- (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 ios 用xcode4.2开发 访问web service的功能
- Our4.org:[时区设定]功能漏洞或致 IPHONE 4S 电池续航减弱
- iPhone开发之CoreLocation定位功能(6)
- cocos2d-iphone 制作倒计时功能
- 专利显示iPhone将有防摔功能
- iPhone 6s 要删除核心功能了,你希望是哪一项?
- ios8定位问题,以及在iphone点击设置隐私定位功能直接崩溃的问题
- iPhone调用短信、邮件等系统功能时界面显示中文的方法
- iphone之使用讯飞语音sdk实现语音识别功能
- iphone之使用讯飞语音sdk实现语音识别功能
- iPhone应用程序推出了市场苹果iOS 4功能
- iPhone的Push(推送通知)功能原理浅析
- iPhone的Push(推送通知)功能原理浅析
- iphone后台功能执行
- iPhone 网络连接检测(Wifi,3G,Edge),功能有点像Reachability
- iPhone开发笔记(2)MPMusicPlayerController和MPMediaPickerController打造如iPod功能类似的播放器
- iphone功能调用代码集合
- 在iphone程序中调用 电话,短信,网页,邮件功能
- 好大夫在线发布新版iPhone客户端 加入LBS功能
- iPhone开发笔记(19)实现类似网易新闻当应用状态变为active时手动调用下拉刷新的功能