Sök…


Enkel nummeranimering

En av de mycket grundläggande animationerna som du kan komma över är NumberAnimation . Denna animering fungerar genom att ändra det numeriska värdet på en egenskap hos ett objekt från ett initialt till ett slutligt tillstånd. Tänk på följande kompletta exempel:

import QtQuick 2.7    
import QtQuick.Controls 2.0    

ApplicationWindow {
    visible: true
    width: 400
    height: 640

    Rectangle{
        id: rect
        anchors.centerIn: parent
        height: 100
        width: 100
        color: "blue"
        MouseArea{
            anchors.fill: parent
            onClicked: na.running = true
        }

        NumberAnimation {
            id: na    //ID of the QML Animation type  
            target: rect    //The target item on which the animation should run  
            property: "height"    //The property of the target item which should be changed by the animator to show effect  
            duration: 200    //The duration for which the animation should run  
            from: rect.height    //The initial numeric value of the property declared in 'property'
            to: 200    //The final numeric value of the property declared in 'property'
        }
    }
}

Beteende-baserad animation

En beteendebaserad animering låter dig ange att ändringen ska animeras över tiden när en egenskap ändras.

ProgressBar {
    id: progressBar
    from: 0
    to: 100
    Behavior on value {
        NumberAnimation {
            duration: 250
        }
    }
}

Om det här exemplet ändrar framstegsfältets värde kommer animationen att animeras över 250 ms



Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow