Ios 如何在两个方向上扩展使用CGMutablePathRef绘制的线?
我正在用铅笔画线Ios 如何在两个方向上扩展使用CGMutablePathRef绘制的线?,ios,iphone,objective-c,ipad,Ios,Iphone,Objective C,Ipad,我正在用铅笔画线 CGMutablePathRef path = CGPathCreateMutable(); for (int i = 0; i < [_points count]; i++) { CGPoint pt = [[_points objectAtIndex:i] CGPointValue]; if (i == 0) { CGPathMoveToPoint(path, NULL, pt.x+1, pt.y+1); }
CGMutablePathRef path = CGPathCreateMutable();
for (int i = 0; i < [_points count]; i++)
{
CGPoint pt = [[_points objectAtIndex:i] CGPointValue];
if (i == 0)
{
CGPathMoveToPoint(path, NULL, pt.x+1, pt.y+1);
}
else
{
CGPathAddLineToPoint(path, NULL, pt.x+1, pt.y+1);
}
}
CGContextSetLineWidth(context, 1.0f);
CGContextSetStrokeColorWithColor(context, curveColor.CGColor);
CGContextAddPath(context, path);
CGContextStrokePath(context);
CGPathRelease(path);
CGMutablePathRef path=CGPathCreateMutable();
对于(int i=0;i<[u点数];i++)
{
CGPoint pt=[[u points objectAtIndex:i]CGPointValue];
如果(i==0)
{
CGPathMoveToPoint(路径,NULL,pt.x+1,pt.y+1);
}
其他的
{
CGPathAddLineToPoint(路径,NULL,pt.x+1,pt.y+1);
}
}
CGContextSetLineWidth(上下文,1.0f);
CGContextSetStrokeColorWithColor(上下文,curveColor.CGColor);
CGContextAddPath(上下文,路径);
CGContextStrokePath(上下文);
CGPathRelease(路径);
我可以把这条线向一个方向延伸。但我想在两个方向(上行和下行)都延伸到一定程度。如何向两个方向延伸直线?要延伸一端:
[_points insertObject:newStartPoint atIndex:0];
另一方面:
[_points addObject:newEndPoint];
终于在@Wain comment的帮助下得到了答案
- (NSArray *)lineDrawingPoints:(CGFloat)slope pointX1:(CGFloat)ptX1 pointY1:(CGFloat)ptY1 maxValX:(CGFloat)biggestNumberX maxValY:(CGFloat)biggestNumberY {
NSMutableArray *infiniteLinePoints = [NSMutableArray array];
float y;
for(int x = -biggestNumberX ; x <= biggestNumberX ; x++ ){
y = slope * (x - ptX1)+ptY1;
if(y >= -biggestNumberY && y <= biggestNumberY )
[infiniteLinePoints addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
}
return infiniteLinePoints;
}
-(NSArray*)线条绘制点:(CGFloat)斜率点x1:(CGFloat)ptX1点y1:(CGFloat)ptY1最大值x:(CGFloat)最大数x最大值:(CGFloat)最大数{
NSMutableArray*infiniteLinePoints=[NSMutableArray];
浮动y;
对于(int x=-biggestNumberX;x=-biggestNumberY&&y),我无法找到newStartPoint和newEndPoint…因此我希望递归扩展,直到该点达到某个限制。如何做?