QML animations visible property changes

前端 未结 6 1235
太阳男子
太阳男子 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:38

    Just for future references, here's my solution which takes care also of Vasco's warning. Basically I'm animating the visible property of the component after the opacity has changed. It hurts seeing a NumberAnimation on a boolean, but it's working:

    states: [
        State{
            name: "Visible"
            PropertyChanges{target: root; opacity: 1.0}
            PropertyChanges{target: root; visible: true}
        },
        State{
            name:"Invisible"
            PropertyChanges{target: root; opacity: 0.0}
            PropertyChanges{target: root; visible: false}
        }
    ]
    
    transitions: [
            Transition {
                from: "Visible"
                to: "Invisible"
    
                SequentialAnimation{
                   NumberAnimation {
                       target: root
                       property: "opacity"
                       duration: 500
                       easing.type: Easing.InOutQuad
                   }
                   NumberAnimation {
                       target: root
                       property: "visible"
                       duration: 0
                   }
                }
            },
            Transition {
                from: "Invisible"
                to: "Visible"
                SequentialAnimation{
                   NumberAnimation {
                       target: root
                       property: "visible"
                       duration: 0
                   }
                   NumberAnimation {
                       target: root
                       property: "opacity"
                       duration: 500
                       easing.type: Easing.InOutQuad
                   }
                }
            }
        ]
    

    This introduces also a transition when the component is vanishing.

提交回复
热议问题