Skip to content

一款白板绘制工具库,支持涂鸦、单箭头、直线、虚线、双箭头直线、双杠直线、椭圆、圆形、矩形、三角形、圆弧、正余弦、梯形、菱形、五边形、六边形、坐标系、直角坐标系、三维坐标系、球体、三菱锥、圆锥、圆柱、立方体数学图形绘制。支持撤销、还原、删除还原功能。

Notifications You must be signed in to change notification settings

hi-zhouyn/ZHFigureDrawingLayer

Repository files navigation

ZHFigureDrawingLayer

ZHFigureDrawingLayer一款图形白板绘制工具库,支持常见的24种数学图形绘制。支持线条颜色、粗细等基本功能设置,新增支持撤销、还原、删除还原操作、图形边界控制、误触点过滤等功能!

预览

ZHFigureDrawingLayer ZHFigureDrawingLayer

文档

简书文档

简介

ZHFigureDrawingLayer支持以下图形,并通过简单的工厂模式,降低耦合,支持快速进行图形新增及修改。白版绘制功能记录手指的开始点和手指一直移动的结束点,中间通过需要实现的图形进行一个关键点计算,以此来进行一个图形绘制,实现一个完整的白版绘制工具库。

typedef enum : NSUInteger {
    ZHFigureDrawingTypeGraffiti = 1,        //涂鸦
    ZHFigureDrawingTypeArrow,               //单箭头
    ZHFigureDrawingTypeLine,                //直线
    ZHFigureDrawingTypeDottedline,          //虚线
    ZHFigureDrawingTypeRulerArrow,          //双箭头直线
    ZHFigureDrawingTypeRulerLine,           //双杠直线
    ZHFigureDrawingTypeOval,                //椭圆
    ZHFigureDrawingTypeCircle,              //圆形
    ZHFigureDrawingTypeRect,                //矩形
    ZHFigureDrawingTypeTriangle,            //三角形
    ZHFigureDrawingTypeArc,                 //圆弧
    ZHFigureDrawingTypeCosine,              //正余弦
    ZHFigureDrawingTypeTrapezoid,           //梯形
    ZHFigureDrawingTypeRhombus,             //菱形
    ZHFigureDrawingTypePentagon,            //五边形
    ZHFigureDrawingTypeHexagon,             //六边形
    ZHFigureDrawingTypeAxis,                //坐标系
    ZHFigureDrawingTypeRighTangle,          //直角坐标系
    ZHFigureDrawingTypeThreeDCoordinate,    //三维坐标系
    ZHFigureDrawingTypeSphere,              //球体
    ZHFigureDrawingTypeTriangularPyramid,   //三菱锥
    ZHFigureDrawingTypeCone,                //圆锥
    ZHFigureDrawingTypeCylinder,            //圆柱
    ZHFigureDrawingTypeCuboid,              //立方体
} ZHFigureDrawingType;

方法定义

/**
 初始化
 @param startPoint      开始点
 @param type            图形类型
 */
+ (instancetype)createLayerWithStartPoint:(CGPoint)startPoint type:(ZHFigureDrawingType)type;

@property (nonatomic, assign) ZHFigureDrawingType drawingType;   //图形类型
@property (nonatomic, strong) NSMutableArray *pointArray;        //记录图形绘制点
@property (nonatomic, assign) CGPoint startPoint;                //起始坐标
@property (nonatomic, assign) CGPoint endPoint;                  //终点坐标
@property (nonatomic, strong) UIColor *lineColor;                //画笔颜色(默认黑色)
@property (nonatomic, assign) CGSize paintSize;                  //画布大小
@property (nonatomic, assign) CGFloat layerLineWidth;            //线宽(1~20,默认2)

- (void)movePathWithStartPoint:(CGPoint)startPoint;
- (void)movePathWithEndPoint:(CGPoint)endPoint;

- (UIBezierPath *)createArrowWithStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;
- (CGFloat)distanceBetweenStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;
- (CGFloat)angleWithFirstPoint:(CGPoint)firstPoint andSecondPoint:(CGPoint)secondPoint;
- (CGFloat)angleEndWithFirstPoint:(CGPoint)firstPoint andSecondPoint:(CGPoint)secondPoint;

意见建议

如果感觉此项目对你有帮助,欢迎Star!如果使用过程中遇到问题或者有更好的建议,欢迎在Issues提出!

更新记录

  • 2020-05-09 增加图形边界控制、误触点过滤功能
  • 2019-12-09 增加线宽设置(layerLineWidth,1~20,默认2)
  • 2019-12-02 增加撤销、还原、删除还原功能

About

一款白板绘制工具库,支持涂鸦、单箭头、直线、虚线、双箭头直线、双杠直线、椭圆、圆形、矩形、三角形、圆弧、正余弦、梯形、菱形、五边形、六边形、坐标系、直角坐标系、三维坐标系、球体、三菱锥、圆锥、圆柱、立方体数学图形绘制。支持撤销、还原、删除还原功能。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published