QML: SequencialAnimation的running属性设置为false,但仍在运行。

3

我在过渡中制作了动画。因此,如果状态更改,则会触发过渡。这是我制作的顺序动画。

SequentialAnimation{
            PropertyAnimation{
                properties: "width"
                duration: 300
            }
            PropertyAnimation{
                properties: "x"
                duration: 500
            }
            Component.onCompleted: {
                var idx = Math.ceil(Math.random()*2);
                if(idx===0){
                    anim0.running = true
                    anim1.running = false
                }
                else {
                    anim1.running = true
                    anim0.running = false
                }
                console.log("haha");
            }
        }

        SequentialAnimation{
            id: anim0
            running: false
            NumberAnimation{
                running: anim0.running
                properties: "x"
                to: 300
                duration: 500
            }
            Component.onCompleted: console.log("anim0");
        }
        SequentialAnimation{
            id: anim1
            running: false
            NumberAnimation{
                running: anim1.running
                properties: "x"
                to: -300
                duration: 500
            }
            Component.onCompleted: console.log("anim1");
        }

在处理Component.onCompleted信号时,先忽略JavaScript代码。 尽管我已将running属性设置为false,但id为anim1和anim0的SequencialAnimation仍然在运行...

1个回答

1

Animation 项的 running 属性设置为 false,不会阻止动画启动。如果当前正在运行,则只会停止它。

如果您不希望在转换中启动动画,请不要将其放在转换内部。您始终可以在 Transition 外部定义自定义 Animation 项,并通过使用 animationId.start() 函数在需要时触发它。

有关详细信息,请参见 文档页面


嗨,谢谢你的帮助。但是,怎么做呢?我需要在sequentialAnimation中调用它吗?还是使用信号?我对QML非常陌生。 - Muhammad Zullidar
这取决于你想做什么... 在哪种情况下你将running属性设置为true? - TheHuge_

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接