我正在构建一个与Figma和Photoshop类似的免费转换工具。到目前为止,我已经计算出旋转,拖动,调整大小从点和纵横比。
我面临的问题是,当缩放组句柄被拖动时,对象移动得太多,缩放得太快。是否有人知道如何使它相对于组家长,请参阅gifs链接以获得澄清。
单次调整的当前位置和尺寸
width: newWidth
height: newHeight
x: newPosition.left
y: newPosition.top到目前为止,我尝试的是增加一些距离,但是值是不确定的。
x: newPosition.left + disnaceX * ???
y: newPosition.top + distanceY * ???我不能公开工作代码,但代码类似于https://github.com/daybrush/moveable/tree/master/packages/react-moveable
我想要的是数学逻辑,它根据它的父级大小来确定应该扩展多少。
当前实现的图像

Figma和Photoshop如何正确运行的图像

发布于 2019-10-24 11:30:00
如果我认为正确,您应该在事件侦听器中执行以下操作:
设newLeft = oldLeft * newCommonWidth / oldCommonWidth
通过求解相同的比例,设newTop = oldTop * newCommonHeight /oldTop每一个元素的新大小,即:
设newElemWidth = oldElemWidth * newCommonWidth / oldCommonWidth
设newElemHeight = oldElemHeight * newCommonHeight /oldElemHeight
https://stackoverflow.com/questions/58539854
复制相似问题