ParentAnimation QML Type
动画显示父节点值的变化。更多
Import Statement: | import QtQuick |
Inherits: |
属性
详细说明
ParentAnimation 用于为Item 的父级变化制作动画。
例如,下面的ParentChange 点击后会将blueRect
变为redRect
的子项。ParentAnimation 定义了在转换过程中应用的NumberAnimation ,它的加入确保了项目在移动到新父对象时的动画效果:
import QtQuick 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 中定义它们。
在某些情况下,例如在启用了剪切功能的项目之间进行再父代时,可以通过另一个未启用剪切功能的项目对父代的变化进行动画处理。可以使用via 属性设置这样的项目。
ParentAnimation 通常在Transition 中与ParentChange 结合使用。以这种方式使用时,它会为状态变化期间发生的任何ParentChange 制作动画。可以通过使用target 属性设置特定的目标项来重写该操作。
另请参阅 Qt Quick和Qt Quick 示例 - 动画中的动画和过渡。
属性文档
newParent : Item |
要制作动画的新父对象。
如果ParentAnimation 定义在Transition 中,则该值默认为Transition 的结束状态中定义的值。
target : Item |
要再父级的项目。
在过渡中使用时,如果未指定目标,则所有ParentChange 出现的ParentAnimation 都会被动画化。
via : Item |
要通过其再现的项目。当新父代和旧父代都被剪切时,这提供了一种做无剪切动画的方法。
ParentAnimation { target: myItem via: topLevelItem // ... }
Transition 注意: 只有在ParentAnimation 与ParentChange 结合使用时才有效。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.