Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用bezierPath和CAShapeLayer绘制的线,不平滑_Objective C_Xcode_Uibezierpath_Cashapelayer_Bezier - Fatal编程技术网

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

Objective c 使用bezierPath和CAShapeLayer绘制的线,不平滑,objective-c,xcode,uibezierpath,cashapelayer,bezier,Objective C,Xcode,Uibezierpath,Cashapelayer,Bezier,我有这个代码来画线的图像用户采取。我已经成功地添加了一个功能,可以在用户的图像上绘制用户想要绘制的内容。但是我画的线不够平滑。我尝试了专家们向其他人建议的答案。但我的看起来仍然粗糙。我的一个特长是用平移手势代替触摸,这会有什么问题吗?需要专家建议和代码。提前谢谢。快乐编码 这就是我调用drawlineFrom方法的地方: -(void)drawLineFrom:(CGPoint)from endPoint:(CGPoint)to { counter++; bezie

我有这个代码来画线的图像用户采取。我已经成功地添加了一个功能,可以在用户的图像上绘制用户想要绘制的内容。但是我画的线不够平滑。我尝试了专家们向其他人建议的答案。但我的看起来仍然粗糙。我的一个特长是用平移手势代替触摸,这会有什么问题吗?需要专家建议和代码。提前谢谢。快乐编码

这就是我调用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];




    }

图像中的线条似乎由大约100个坐标组成。然而,在代码中,您只需要知道如何在一对坐标之间画一条线。因此,图像中的红色似乎不是来自单个路径,而是来自100个单独的线段。这就解释了为什么它们看起来那么粗糙。为了画一条平滑的连续线,你必须使用一条包含所有坐标的贝塞尔路径。我在用户触摸的地方画方框。我现在就是这样画的。还有其他方法吗?我试过画圆,但这给了我清晰的圆,而不是连续的圆柱形路径。如果我用PanGesture而不是Uitouchin,你画了数百条短线段,有什么问题吗。这不是你想要达到的,也是它看起来如此参差不齐的原因。您必须记录所有坐标并将它们合并到一条路径中。这可能意味着,在每次触摸移动事件中,您必须从屏幕上删除当前路径,向其中添加一个坐标,然后再次添加。您在哪里调用drawLineFrom?