使用CAShapeLayer绘制两条平行线

时间:2012-02-10 14:48:44

标签: iphone objective-c ios draw cashapelayer

我正在通过

绘制单行
CAShapeLayer *lineShape = nil;
CGMutablePathRef linePath = nil;
linePath = CGPathCreateMutable();
lineShape = [CAShapeLayer layer];

lineShape.lineWidth = 1.0f;
lineShape.lineCap = kCALineJoinMiter;
lineShape.strokeColor = [[UIColor redColor] CGColor];


CGPathMoveToPoint(linePath, NULL, x, y);
CGPathAddLineToPoint(linePath, NULL, toX, toY);

lineShape.path = linePath;
CGPathRelease(linePath);

[myView.layer addSublayer:lineShape];

我想在这一行画一条平行线。有什么想法或计算吗?

或者是否有任何代码可以获取此特定行的触摸点。实际上我可以在两条线之间触摸时获得触摸点,并且从 CGPathContainsPoint 方法我可以获得两条线之间的触点,因此我想在这里创建两条平行线。

1 个答案:

答案 0 :(得分:0)

Line geometry

enter image description here

enter image description here

b - 班次。你需要转换坐标