我需要用react-konva做圆角垂直线,用现有的API能实现吗?如果是,是如何实现的?
我使用bezier API for Line类,它工作得很好。不知何故,现在我需要修改贝塞尔曲线,使其成为四舍五入的垂直线。
像这样的东西:

发布于 2019-05-15 08:19:44
有很多方法可以实现它。可以使用tension创建曲线,也可以使用lineCap特性。
但为了有更多的控制,最好是创建自定义形状。
const RADIUS = 20;
const Line = ({ points }) => {
return (
<Shape
points={points}
sceneFunc={(context, shape) => {
const width = points[1].x - points[0].x;
const height = points[1].y - points[0].y;
const dir = Math.sign(height);
const radius = Math.min(RADIUS, Math.abs(height / 2), Math.abs(width / 2));
context.beginPath();
context.moveTo(points[0].x, points[0].y);
context.lineTo(points[0].x + width / 2 - RADIUS, points[0].y);
context.quadraticCurveTo(
points[0].x + width / 2,
points[0].y,
points[0].x + width / 2,
points[0].y + dir * radius
);
context.lineTo(points[0].x + width / 2, points[1].y - dir * radius);
context.quadraticCurveTo(
points[0].x + width / 2,
points[1].y,
points[0].x + width / 2 + radius,
points[1].y
);
context.lineTo(points[1].x, points[1].y);
context.fillStrokeShape(shape);
}}
stroke="black"
strokeWidth={2}
/>
);
};https://stackoverflow.com/questions/56095148
复制相似问题