【问题标题】:Is there a way to prevent a Shape for being transformed?有没有办法防止 Shape 被转换?
【发布时间】:2021-12-03 23:25:59
【问题描述】:

就是这样,我正在创建一个覆盖所有画布的形状以充当白色背景,我有一个变压器,我正在听画布点击,在其中我将对象添加到变压器节点中,但我没有喜欢变换我用作背景的白色形状。

Canvas white Shape

【问题讨论】:

    标签: vuejs3 konvajs


    【解决方案1】:

    只是不要在其中添加变压器。我看到了几个解决方案:

    1. 在该背景形状上设置listening = false。在这种情况下,它不会触发任何鼠标/触摸/指针事件
    2. 或者在click回调中为它设置一个特殊的名字就忽略
    const background = new Konva.Rect({
      fill: 'white',
      width: stage.width(),
      height: stage.height(),
      name: 'nonSelectable'
    });
    
    
    
    stage.on('click', (e) => {
      // ignore such shape
      if (e.target.hasName('nonSelectable')) {
        return;
      }
      // else attach transformer
    });
    

    【讨论】:

    • 谢谢@lavrton!!
    猜你喜欢
    • 1970-01-01
    • 2015-11-11
    • 2019-02-15
    • 2018-09-11
    • 2012-10-17
    • 1970-01-01
    • 2020-10-10
    • 2010-09-06
    • 1970-01-01
    相关资源
    最近更新 更多