iOS实现白板、画板功能,有趣的涂鸦工具,已封装,简单快捷使用
2017-02-10 10:00
671 查看
一、效果图:
二、选择颜色:
分【固定颜色模式】和【自由取模式】。
三、操作栏功能:
1、撤销:撤销上一步操作,可一直往上进行,直到全部清空。
2、清空:直接清除所有绘画。
3、橡皮擦:去除不要的绘画部分。
4、保存:一键保存相册。
四、实现方式:
贝塞尔曲线结合drawrect绘画。
代码结构:
核心代码模块:
外部引用代码:
简单吧~
五、源码获取:
我直接把我的测试Demo放上去了,大家下载后,直接定位画板功能即可。
《点击这里获取全部源码》
二、选择颜色:
分【固定颜色模式】和【自由取模式】。
三、操作栏功能:
1、撤销:撤销上一步操作,可一直往上进行,直到全部清空。
2、清空:直接清除所有绘画。
3、橡皮擦:去除不要的绘画部分。
4、保存:一键保存相册。
四、实现方式:
贝塞尔曲线结合drawrect绘画。
代码结构:
核心代码模块:
#pragma mark - 画画 -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; self.bezierPath = [[YJBezierPath alloc] init]; self.bezierPath.lineColor = self.lineColor; self.bezierPath.isErase = self.isErase; [self.bezierPath moveToPoint:currentPoint]; [self.beziPathArrM addObject:self.bezierPath]; } -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; CGPoint previousPoint = [touch previousLocationInView:self]; CGPoint midP = midpoint(previousPoint,currentPoint); // 这样写不会有尖头 [self.bezierPath addQuadCurveToPoint:currentPoint controlPoint:midP]; [self setNeedsDisplay]; } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self]; CGPoint previousPoint = [touch previousLocationInView:self]; CGPoint midP = midpoint(previousPoint,currentPoint); [self.bezierPath addQuadCurveToPoint:currentPoint controlPoint:midP]; // touchesMoved [self setNeedsDisplay]; }
-(void)drawRect:(CGRect)rect{ if (self.beziPathArrM.count) { for (YJBezierPath *path in self.beziPathArrM) { if (path.isErase) { [self.backgroundColor setStroke]; }else{ [path.lineColor setStroke]; } path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineCapRound; if (path.isErase) { path.lineWidth = 10; // 这里可抽取出来枚举定义 [path strokeWithBlendMode:kCGBlendModeDestinationIn alpha:1.0]; }else{ path.lineWidth = 3; [path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; } [path stroke]; } } [super drawRect:rect]; }
外部引用代码:
#import "BaiBanViewController.h" #import "BaibanView.h" @interface BaiBanViewController () @property (nonatomic,strong) BaibanView *baibanV; @end @implementation BaiBanViewController -(BaibanView *)baibanV{ if(_baibanV==nil){ _baibanV=[[BaibanView alloc] initWithFrame:CGRectMake(0, 64, KScreenWidth, KScreenHeight - 64)]; } return _baibanV; } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"画 板"; [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; self.view.backgroundColor = [UIColor whiteColor]; //添加画板功能 [self.view addSubview:self.baibanV]; }
简单吧~
五、源码获取:
我直接把我的测试Demo放上去了,大家下载后,直接定位画板功能即可。
《点击这里获取全部源码》
相关文章推荐
- swift涂鸦功能的实现包括截图,画板封装,文本编辑,分享功能,橡皮擦功能,马赛克技术
- IOS开发之使用Speex格式实现简单的语音聊天功能(二)
- IOS开发之使用Speex格式实现简单的语音聊天功能(一)
- ios-day20-01(使用UIWebView实现一个简单功能的浏览器)
- IOS开发之使用Speex格式实现简单的语音聊天功能(二)
- 使用bitmapData简单实现涂鸦中的橡皮功能(as3)
- iOS_通过UIBezierPath实现简单的画板功能
- 使用bitmapData简单实现涂鸦中的橡皮功能[Flex]
- IOS实现的简单画板功能
- IOS开发之使用Speex格式实现简单的语音聊天功能(一)
- 使用NetBox简单实现ASP封装为EXE教程
- 用Python 实现刷钻网上抢任务,并实现一个简单的限制使用时间的功能
- XNA Game Studio是一套有着强大功能和简单界面的游戏制作平台,游戏开发商和游戏玩家都可以使用这套工具开发针对Windows XP以及Xbox360的游戏,XNA Game Studio分为两种版本,一种是面向初学者的EXPRESS版本,还有一种是面向专业用户的专业版。用户使用EXPRESS版本开发游戏完全免费,并且可以随意在PC上发行,不过用该工具开发的游戏若是在360上网络发行,就需要交纳99美元的年费。
- J2EE实践第四部分-使用SAP CAF实现功能的简单小例子
- 使用jQuery方便快捷的实现Ajax功能
- 使用FLEX实现简单WEB在线拍照功能
- 使用Javascript实现一种简单的数字混淆功能(高手绕过)
- 使用 Raphael js 和JSON 来实现具备保存功能的简单的仿QQ秀
- 使用NetBox简单实现ASP封装为EXE教程
- 简单快捷实现ASP在线发邮件功能