QML animations visible property changes

前端 未结 6 1259
太阳男子
太阳男子 2021-02-13 08:52

I want an animation to be painted when an element becomes visible (is should appear smoothly, not the whole at all)

I tried this

states: State
{
    name         


        
6条回答
  •  走了就别回头了
    2021-02-13 09:31

    visibility can be used in NumberAnimation, but to get the needed fading result, opacity animation could be used; like turning visibility ON from function like the following example:

    Rectangle{
        id:fadingRect
        anchors.fill: parent
        visible: false
        opacity: 0.00
        color: "red"
        Component.onCompleted: {
            animRect.start()
        }
    }
    SequentialAnimation{
        id:animRect
        NumberAnimation { target: fadingRect; property: "visible"; from: 0; to:1; duration: 20}
        NumberAnimation { target: fadingRect; property: "opacity"; from: 0.00; to:1.00; duration: 4000 }
    
        onStopped: console.log(fadingRect.visible)
    }
    

    Or :

    Rectangle{
        id:fadingRect
        anchors.fill: parent
        visible: false
        opacity: 1
        color: "red"
        Component.onCompleted: {
            animRect.start()
        }
            NumberAnimation { id:animRect; target: fadingRect; property: "opacity"; from: 0; to:1; duration: 2000;
            onStarted: { fadingRect.visible=true; console.log(fadingRect.visible)}
            }
    }
    

提交回复
热议问题