【发布时间】:2012-07-16 01:17:07
【问题描述】:
我在使用四边形曲线点时遇到点问题。我想为我的线条设置不透明度,但我也在这里看到了点。 这是我的代码..
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;
}
任何答案将不胜感激。
【问题讨论】:
-
我认为问题在于您绘制的每条曲线的末端与下一条曲线的开头重叠。不幸的是,我无法立即想到解决此问题的简单方法。你画的是什么背景?
-
您能否提供更多有关您要完成的工作的背景信息?乍一看,这比仅使用 UIGestureRecognizer 跟踪触摸并覆盖 drawRect 进行绘图要复杂得多。
-
我只想在一个空的 UIImageView 中画一条线,可以设置它的不透明度..
-
您使用 UIImageView 而不是 UIView 的任何原因?
-
用简单的英语来说,问题是您正在绘制许多重叠的线而不是单个路径。 user1118321 的回答很好:他/她向您展示了如何收集点并绘制整个路径而不是添加单独的线,这应该可以解决您的问题。
标签: iphone objective-c ios xcode