父类:Animation
子类:无
2.综述ParentAnimation用于动画一个项目的父变化。
例如,下面的ParentChange在单击blueRect时将其更改为redRect的子对象。ParentAnimation,定义了一个在过渡期间应用的NumberAnimation,确保项目移动到它的新父元素时动画平滑:
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Item {
width: 200; height: 100
Rectangle {
id: redRect
width: 100; height: 100
color: "red"
}
Rectangle {
id: blueRect
x: redRect.width
width: 50; height: 50
color: "blue"
states: State {
name: "reparented"
ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }
}
transitions: Transition {
ParentAnimation {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
}
MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" }
}
}
}
一个ParentAnimation可以包含任意数量的动画。这些动画将并行运行;要按顺序运行它们,请在SequentialAnimation中定义它们。
在某些情况下,例如在启用了剪切的项之间重parent时,通过另一个没有启用剪切的项来动画父项更改是很有用的。这样的项可以使用via属性设置。
ParentAnimation通常与ParentChange一起在Transition中使用。当以这种方式使用时,它会动画状态变化期间发生的任何ParentChange。这可以通过使用target属性设置特定的目标项来覆盖。
参见Qt Quick中的Animation and Transitions in Qt Quick and Qt Quick Examples - Animation.
3.1 newParent : Item
动画父对象。
如果ParentAnimation是在Transition中定义的,则该值默认为Transition结束状态中定义的值。
3.2 target : Item重定父级的Item。
当在转换中使用时,如果没有指定目标,所有的ParentChange事件都由ParentAnimation动画。
提供了一种方法,当旧父节点和新父节点都被剪切时执行未剪切的动画。
ParentAnimation {
target: myItem
via: topLevelItem
// ...
}
注意:这只在ParentAnimation与ParentChange结合使用的过渡中起作用。



