画图4

作者: nothing_c | 来源:发表于2016-10-30 23:36 被阅读11次

    简易画板画图


    {

    //画布用于显示的图层

    CAShapeLayer *_layer;

    //用于记录移动点路径

    UIBezierPath *_beziePath;

    }

    - (void)viewDidLoad {

    [super viewDidLoad];

    //

    _layer = [CAShapeLayer layer];

    _layer.frame = self.view.frame;

    _layer.backgroundColor = [UIColorcyanColor].CGColor;

    _layer.strokeColor = [UIColororangeColor].CGColor;

    _layer.lineWidth = 5;

    //@[@10]虚线

    //@[@10,@0]实线

    _layer.lineDashPattern = @[@10,@0];

    _layer.fillColor = [UIColorclearColor].CGColor;

    _layer.lineCap = @"round";

    _layer.lineJoin = @"round";

    [self.view.layer addSublayer:_layer];

    _beziePath = [[UIBezierPath alloc] init];

    _layer.path =_beziePath.CGPath;

    }

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint point = [[touches anyObject] locationInView:self.view];

    [_beziePath moveToPoint:point];

    }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint point = [[touches anyObject] locationInView:self.view];

    [_beziePath addLineToPoint:point];

    _layer.path =_beziePath.CGPath;

    }

    相关文章

      网友评论

          本文标题:画图4

          本文链接:https://www.haomeiwen.com/subject/dfwuuttx.html