2017-06-08 22 views
1

是否可以在某個時間點臨時禁用(忽略/不顯示)複雜QML組件上的動畫?然後激活動畫並照常工作。臨時禁用(忽略/不顯示)複雜QML組件上的動畫

例如。 QML上的複雜頁面顯示對象的數據,有許多小動畫。更改數據對象時,應忽略這些動畫。

Rectangle { 
    anchors.fill: parent 
     property variant cppViewModel: MyCppViewModel { 
      onBeforDataObjectChanged: { 

      } 
      onAfterDataObjectChanged: { 

      } 
     } 

    Rectangle { 
     id: idRect1 
     Behavior on x { NumberAnimation { ... }} 
     Behavior on y { NumberAnimation { ... }} 
     x: cppViewModel.dataObject.offsetX 
     y: cppViewModel.dataObject.offsetY 
     scale: cppViewModel.dataObject.scale 

     Rectangle { 
      id: idRect2 

      width: cppViewModel.dataObject.width 
      heigth: cppViewModel.dataObject.heigth 
      Behavior on width { NumberAnimation { ... }} 
      Behavior on heigth { NumberAnimation { ... }} 

      ColumnLayout { 
       Rectangle { 
        Layout.preferredHeight: 100 * cppViewModel.dataObject.width1 
        Behavior on Layout.preferredHeight { NumberAnimation { duration: 500; easing.type: Easing.OutQuad; }} 
        //... Any number of children with animation 
       } 
      } 
     } 
    } 

    PropertyAnimation { target: idRect1; property: "scale"; from: 0.9; to: 1.0; ... } 
} 

如果當前數據對象的屬性值發生變化,則需要動畫。如果整個對象更改爲另一個,則需要阻止該動畫。

+0

嗨,你可以請廣告一些代碼,以幫助我的想象力?但我認爲答案是**是** – derM

+0

已添加。實際代碼超過2000行。 –

+0

所以它是關於那些行爲? – derM

回答

1

要禁用Animation s有多種方法,正確的取決於Animation的啓動方式。

如果Animation通過設置running-property開始,你可以簡單地添加一個&& animationsEnabled 的條件,其中animationsEnabled是你必須到別處定義並相應地切換它的屬性。

如果您使用功能:run()開始您的Animation,解決方案是,到不做

如果使用Animation whithin一個Behavior可以使用Behaviors enabled-property停用Behavior及其Animation

最後我可以想到Transition s。正如BehaviorTransition has a enabled-property,將其停用。

我希望我沒有忘記一種動畫的方式,你會找到適合你的問題的解決方案!