Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Iphone 目标C:如何使用四次曲线中的alpha绘制直线_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 目标C:如何使用四次曲线中的alpha绘制直线

Iphone 目标C:如何使用四次曲线中的alpha绘制直线,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,当我使用四次曲线点时,我在点方面遇到了问题。。我想为我的线条设置不透明度,但我在这里也看到了点。。 这是我的密码 CGPoint midPoint(CGPoint p1,CGPoint p2) { return CGPointMake ((p1.x + p2.x) * 0.5,(p1.y + p2.y) * 0.5); } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event//upon touches {

当我使用四次曲线点时,我在点方面遇到了问题。。我想为我的线条设置不透明度,但我在这里也看到了点。。 这是我的密码

CGPoint midPoint(CGPoint p1,CGPoint p2)
{
    return CGPointMake ((p1.x + p2.x) * 0.5,(p1.y + p2.y) * 0.5);
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event//upon touches
{
    UITouch *touch = [touches anyObject];

    previousPoint1 = [touch locationInView:self.view];
    previousPoint2 = [touch locationInView:self.view];
    currentTouch = [touch locationInView:self.view];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event//upon moving
{
    UITouch *touch = [touches anyObject];

    previousPoint2 = previousPoint1;
    previousPoint1 = currentTouch;
    currentTouch = [touch locationInView:self.view];

    CGPoint mid1 = midPoint(previousPoint2, previousPoint1); 
    CGPoint mid2 = midPoint(currentTouch, previousPoint1);

    UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
    [imgDraw.image drawInRect:CGRectMake(0, 0, 1024, 768)];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineCap(context,kCGLineCapRound);
    CGContextSetLineWidth(context, slider.value);
    CGContextSetBlendMode(context, blendMode);
    CGContextSetRGBStrokeColor(context,red, green, blue, 0.5);
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, mid1.x, mid1.y);
    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
    CGContextStrokePath(context);

    imgDraw.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsGetCurrentContext();
    endingPoint=currentTouch;
}

任何答案都将不胜感激。

您需要做的是保留用户迄今为止输入的所有点的列表,并始终将它们作为同一路径的一部分重新绘制

需要一个数组来存储点。差不多

CGPoint points[kMaxNumPoints];
而不是以前的点1/2等。然后在
触摸移动:
中,您将在循环中迭代这些点。大概是这样的:

CGContextBeginPath (context);
CGContextMoveToPoint (context, points [ 0 ].x, point [ 0 ].y);
for (int i = 1; i < currNumPoints; i++) 
{
    // I wasn't sure from your example if you wanted the mid point here instead of the 
    // previous point. But you get the idea.
    CGContextAddQuadCurveToPoint (context, points [ i - 1 ].x, points [ i - 1 ].y, point [ i ].x, point [ i ].y);
}
CGContextStrokePath (context);
CGContextBeginPath(上下文);
CGContextMoveToPoint(上下文,点[0].x,点[0].y);
对于(int i=1;i
您需要做的是保留用户迄今为止输入的所有点的列表,并始终将它们作为同一路径的一部分重新绘制

需要一个数组来存储点。差不多

CGPoint points[kMaxNumPoints];
而不是以前的点1/2等。然后在
触摸移动:
中,您将在循环中迭代这些点。大概是这样的:

CGContextBeginPath (context);
CGContextMoveToPoint (context, points [ 0 ].x, point [ 0 ].y);
for (int i = 1; i < currNumPoints; i++) 
{
    // I wasn't sure from your example if you wanted the mid point here instead of the 
    // previous point. But you get the idea.
    CGContextAddQuadCurveToPoint (context, points [ i - 1 ].x, points [ i - 1 ].y, point [ i ].x, point [ i ].y);
}
CGContextStrokePath (context);
CGContextBeginPath(上下文);
CGContextMoveToPoint(上下文,点[0].x,点[0].y);
对于(int i=1;i
我认为问题在于您绘制的每条曲线的末端与下一条曲线的起点重叠。不幸的是,我不能马上想出一个简单的解决这个问题的办法。你的背景是什么?你能提供一些你想要完成的事情的背景吗?乍一看,这比仅仅使用UIGestureRecognitor跟踪触摸和覆盖drawRect进行绘制要复杂得多。我只想在空的UIImageView中绘制一条线,可以设置它的不透明度。你为什么使用UIImageView而不是UIView?问题是,用简单的英语说,就是你画了很多重叠的线,而不是一条单独的路径。user1118321的回答很好:他/她向您展示了如何收集点并绘制整个路径,而不是添加单独的线,这应该可以解决您的问题。我认为问题在于,您绘制的每条曲线的末端与下一条曲线的起点重叠。不幸的是,我不能马上想出一个简单的解决这个问题的办法。你的背景是什么?你能提供一些你想要完成的事情的背景吗?乍一看,这比仅仅使用UIGestureRecognitor跟踪触摸和覆盖drawRect进行绘制要复杂得多。我只想在空的UIImageView中绘制一条线,可以设置它的不透明度。你为什么使用UIImageView而不是UIView?问题是,用简单的英语说,就是你画了很多重叠的线,而不是一条单独的路径。user1118321的回答很好:他/她向您展示了如何收集点并绘制整个路径,而不是添加单独的线,这应该可以解决您的问题。当我尝试实现给定代码时,我注释了我的CGContextMoveToPoint和CGContextAddQuadCurveToPoint。。问题是你删除了制作四次曲线的2点。。很抱歉,我刚刚了解了逻辑,但我不知道如何使用给定的代码..:(我已经更新了上面的代码,向您展示了我的全部代码..希望这一次能让您更容易。当我尝试实现您给定的代码时,我注释了我的CGContextMoveToPoint和CGContextAddQuadCurveToPoint..问题是您删除了制作四次曲线的2点..很抱歉,我只知道逻辑,但我不知道如何使用您给定的代码..(我已经更新了上面的代码,向您展示了我的全部代码..希望这一次对您来说更容易。