我想请一些帮助。在我的应用程序中,矩形需要粘在网格上。我找到了一种在拖动网格时跟随网格的解决方案,但是在调整大小的情况下,我无计可施。使用以下代码达到一个网格单元大小需要 5 个步骤:
this.selectedElement.on('transform', () => {
let stepW = (this.blockSizeW / (this.stage.width() / 2));
let stepH = (this.blockSizeH / (this.stage.height() / 2));
this.selectedElement.scale({
x: Math.round(this.selectedElement.scaleX() / stepW) * stepW,
y: Math.round(this.selectedElement.scaleY() / stepH) * stepH,
});
});
变换后的矩形:
此外,矩形有奇怪的行为。缩放仅适用于向右和底部方向,当我尝试拖动左侧或顶部锚点时,整个矩形移动缓慢而不是缩放。任何想法将不胜感激!
我用angular 10
,Konva 7.1.0