0

我想停止这样的动画:

Behavior on x {
    NumberAnimation {
        id: animationElement
         duration: 100
    }
}
    ...
if (something)
{
    animationElement.stop()
}

但是这段代码给了我错误,stop() 不能在非根动画节点上使用。它可能从外部停止动画?

4

1 回答 1

1

这对我来说很好:

import QtQuick 1.0

Rectangle
{
    color: "grey"
    width:  800
    height: 800

    NumberAnimation on width { id: animationElementw ;  from: 800; to: 500; duration: 8500 }
    NumberAnimation on height { id: animationElementH ;  from: 800; to: 500; duration: 8500 }

    MouseArea
    {
      anchors.fill: parent
      onClicked:
      {
          animationElementw.stop()
          animationElementH.stop()
      }
    }

    Text
    {
        id: name
        anchors.centerIn: parent
        text: "Click me to stop shrinking animation!!!"
        color: "white"
        font.pixelSize: 25
    }
}
于 2013-01-16T12:56:09.020 回答