使用动画向转发器添加元素

and*_*rew 2 javascript qt qml qt-quick qtquick2

我有一个转发器,它们在创建时被动画化.

Repeater {
    model : 0

    Image {
       ...

       Animation {
           ...
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我在上一个元素的动画结束后向模型添加元素,那么一切都正常.但如果我之前添加一个eleent,它就无法工作.例如,如果我有枪射击子弹,如果我等到子弹的动画结束一切正常.但如果我想在第一个结束之前拍摄另一个子弹,第一个消失,我只看到第二个动画.

我该怎么做才能看到所有的动画?

The*_*roo 7

也许你的模型或你的代表有问题,或者布局(项目重叠......),因为这里工作正常:

import QtQuick 2.0;

Rectangle {
    width: 400;
    height: 300;

    Timer {
        running: true;
        repeat: true;
        interval: 1000;
        onTriggered: { modelTest.append ({ "bg" : Qt.hsla (Math.random (), 0.85, 0.45, 1.0).toString () }); }
    }
    Flow {
        anchors.fill: parent;

        Repeater {
            model: ListModel {
                id: modelTest;
            }
            delegate: Rectangle {
                id: rect;
                color: model.bg;
                width: 50;
                height: width;
                scale: 0.0;

                PropertyAnimation {
                    target: rect;
                    property: "scale";
                    from: 0.0;
                    to: 1.0;
                    duration: 450;
                    running: true;
                    loops: 1;
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请记住,只有ListModel和QAbstractListModel能够动态添加新项而不重置整个委托,另一个(变量列表,JS数组,数字)将导致所有委托在每次模型修改时重新实现...