自制画板
来源:互联网 发布:如何设置域名重定向 编辑:程序博客网 时间:2024/05/17 07:25
效果
重点代码
@implementation GSDrawFunView{ NSMutableArray * mShapeLayerArray; // 总layer数组,里面有好多线,每条线由下面数组组成 NSMutableArray * mCurrentShapeLayerArray; // 当前画的线的layer数组 NSMutableArray * mBezierPathArray; // 所有path数组 UIColor * mCurrentColor; UIView * mDrawBoardView;}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch * touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; //控制画板位置,防止线画出画板 if (point.x < mDrawBoardView.x || point.y < mDrawBoardView.y || point.x > CGRectGetMaxX(mDrawBoardView.frame) || point.y > CGRectGetMaxY(mDrawBoardView.frame)) { return; } //每条线开始画都要初始化path UIBezierPath * currentBezierPath = [[UIBezierPath alloc]init]; [currentBezierPath moveToPoint:point]; [mBezierPathArray addObject:currentBezierPath]; //每条线开始画都要初始化layer数组 mCurrentShapeLayerArray = [[NSMutableArray alloc]init]; }-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch * touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; if (point.x < mDrawBoardView.x || point.y < mDrawBoardView.y || point.x > CGRectGetMaxX(mDrawBoardView.frame) || point.y > CGRectGetMaxY(mDrawBoardView.frame)) { return; } UIBezierPath * currentBezierPath = [mBezierPathArray lastObject]; [currentBezierPath addLineToPoint:point]; CAShapeLayer * currentLayer = [[CAShapeLayer alloc]init]; currentLayer.path = currentBezierPath.CGPath; currentLayer.fillColor = nil; currentLayer.strokeColor = mCurrentColor.CGColor; currentLayer.lineJoin = kCALineJoinRound; //终点 currentLayer.lineCap = kCALineCapRound; //拐角 currentLayer.lineWidth = 2; [self.layer addSublayer:currentLayer]; [mCurrentShapeLayerArray addObject:currentLayer]; }-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //每条线画完,都要添加到layer数组里 [mShapeLayerArray addObject:mCurrentShapeLayerArray];}//改变画笔颜色-(void)changeColorForPaintBrushWithColor:(UIColor *)color{ mCurrentColor = color; }//撤销-(void)remokeLineAction{ //删除path UIBezierPath * lastBezierPath = [mBezierPathArray lastObject]; [lastBezierPath removeAllPoints]; [mBezierPathArray removeLastObject]; //删除layer NSArray * lastShapeLayerArray = [mShapeLayerArray lastObject]; [mShapeLayerArray removeLastObject]; for (CAShapeLayer * layer in lastShapeLayerArray) { [layer removeFromSuperlayer]; } }
阅读全文
1 0
- 自制画板
- android 模仿windows 自制画板
- 画板
- 画板
- 画板
- 画板
- 自制
- 做画板
- JS画板
- WP7 ,画板
- ios 画板
- 简易画板
- 涂鸦画板
- 画板案例
- Android画板
- Bitmap画板
- 画板记录
- 画板 ios
- [转] 一段双线性插值的代码
- js 单引号 双引号转义
- 手把手教你使用自定义dialog,可以出现在任意位置
- Android Gson详解(四)
- 设计模式三
- 自制画板
- NKOJ 3697 乒乓比赛
- ueditor 遇到的错误
- 网络套接字socket编程之UDP
- PAT (Advanced Level) Practise 1064 Complete Binary Search Tree (30)
- 2017ccpc全国邀请赛(湖南湘潭) H. Highway XTOJ 1267 【树的直径】
- Best Paper Awards in Computer Science (since 1996)
- 互联网开发-web文件上传性能问题
- 分针网——每日分享:Vue 指令总结