使用bezierPath和CAShapeLayer绘制的线条,不平滑

时间:2016-05-11 05:22:16

标签: objective-c xcode uibezierpath cashapelayer bezier

我有这个代码在图像用户拍摄时绘制线条。我已成功添加功能来绘制用户在他/她的图像上绘制的内容。但是我绘制的线条不够平滑。我已经尝试过堆栈溢出专家向其他人建议的答案。但我的看起来仍然很粗糙。一个特点是我使用平移手势而不是触摸,这会产生任何问题吗?需要专家建议和代码。提前致谢。快乐的编码。 !

The lines on the picture looks rough, not smooth

这是我称之为drawlineFrom方法的地方:

  -(void)drawLineFrom:(CGPoint)from endPoint:(CGPoint)to
    {
    counter++;
    bezierPath = UIBezierPath.bezierPath;

    NSLog(@"UIGestureRecognizerStateChanged here");

    [bezierPath moveToPoint: CGPointMake(from.x, from.y)];


   [bezierPath addLineToPoint:CGPointMake(to.x, to.y)];


    [bezierPath closePath];
    bezierPath.usesEvenOddFillRule = YES;
    box = [CAShapeLayer layer];
    box.frame = CGRectMake(0, 0, 500, 500);
    box.path = bezierPath.CGPath;
    box.strokeColor = [UIColor colorWithRed:0.992 green:0.322 blue:0.212 alpha:1.00].CGColor;
    box.fillColor = [UIColor colorWithRed:0.992 green:0.322 blue:0.212 alpha:1.00].CGColor;
    box.lineWidth = 5;

    [self.myImage.layer addSublayer:box ];

    [layerarray addObject:box];
    NSLog(@"AAAAARRRRTTTT%@",layerarray);

    }



{

    startPoint = [gesture locationInView:self.selfieImage];

    if(gesture.state == UIGestureRecognizerStateChanged)
    {
        NSLog(@"Touched here \n :X-%f \n Y-%f",[gesture locationInView:self.selfieImage].x,[gesture locationInView:self.selfieImage].y);
        startPoint = lastPoint;
        lastPoint = [gesture locationInView:self.selfieImage];
        [self drawLineFrom:startPoint endPoint:lastPoint];




    }

0 个答案:

没有答案