画图3

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

    画板画图


    {

    UIImageView *_canvasImageView;

    //起点

    CGPoint _startPoint;

    }

    - (void)viewDidLoad {

    [super viewDidLoad];

    _canvasImageView = [[UIImageView alloc] init];

    _canvasImageView.frame = self.view.frame;

    [self.view addSubview:_canvasImageView];

    }

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

    //开始触摸记录初始触摸点坐标

    _startPoint = [[touches anyObject] locationInView:_canvasImageView];

    }

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

    //移动点坐标

    CGPoint movePoint = [[touches anyObject] locationInView:_canvasImageView];

    //释放池

    @autoreleasepool {

    UIGraphicsBeginImageContext(_canvasImageView.bounds.size);

    [_canvasImageView drawRect:_canvasImageView.bounds];

    CGContextRefcontext = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 20);

    CGContextSetRGBStrokeColor(context, 0, 1, 0.5, 1);

    CGContextSetLineCap(context,kCGLineCapRound);

    CGContextSetLineJoin(context,kCGLineJoinRound);

    CGContextMoveToPoint(context,_startPoint.x,_startPoint.y);

    CGContextAddLineToPoint(context, movePoint.x, movePoint.y);

    CGContextStrokePath(context);

    UIImage *image  =UIGraphicsGetImageFromCurrentImageContext();

    _canvasImageView.image = image;

    UIGraphicsEndPDFContext();

    _startPoint = movePoint;

    }

    }

    相关文章

      网友评论

          本文标题:画图3

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