我正在製作一個圖像編輯器,它可以創建不同形狀的對象,如圓形,三角形和方形,這些對象也可以更新或刪除。所以我用CAShapeLayer
來創建形狀對象。使用CAShapeLayer對象繪製與Bezierpath的線
現在我也想在圖像上畫一條線,也可以更新或刪除,所以我用了bezierpath和CAShapeLayer
來創建線條,它工作的很好。但現在的問題是,當我想選擇任何現有的線時,可以在靠近線工具的地方選擇任何線,因爲CAShapeLayer
也設置了從起點到終點的直線的填充區域。
我的問題是,如何使用CAShapeLayer
創建沒有填充區域的行。
這裏是我創建一行代碼:
CAShapeLayer *line = [CAShapeLayer layer];
// Using bezierpath to make line
UIBezierPath *linePath=[UIBezierPath bezierPath];
// Creating L with line
[linePath moveToPoint:point1];
[linePath addToPoint:point2];
[linePath addToPoint:point3];
line.path=linePath.CGPath;
// Configure the appearence of the line
line.fillColor = Nil;
line.opacity = 1.0;
line.strokeColor = [UIColor whiteColor].CGColor;
對此有何想法會非常感激。
它的工作原理。可能你忘了添加圖層'''[self.view.layer addSublayer:line];''' – Shmidt
我也添加了這一行,它創建的線條很好,但它也填充區域從起點到終點並考慮它作爲圖層的一部分。所以問題在於,每當我嘗試在線路層附近點擊時都會被選中。 –
你應該使用'[linePath addLineToPoint:point2]'? –