zoukankan      html  css  js  c++  java
  • qml----动画入门(二、简单的动画实现 NumberAnimation、ColorAnimation类)

    上一节中我们讲了PropertyAnimation类,现在我们来讲讲专门处理数字类型的property。

    说起这个NumberAnimation,与PropertyAnimation是表亲,有很多相同的血缘关系,但是塔又重写了from和to两种属性,改成了real类型。下面来个小例子看看

    import QtQuick 2.2
    
    Rectangle{
        id: rootItem
         360
        height: 240
        color: "#EEEEEE"
    
        Rectangle{
            id: rect
             50
            height: 50
            x: 0
            y: 5
            color: "blue"
    
            MouseArea{
                id: mouseArea
                anchors.fill: parent
                onClicked: {
                    animationX.start()
                    animationRotation.running = true
                    animationRadius.start()
                }
            }
    
            NumberAnimation{
                id: animationX
                target: rect
                properties:  "x, y"
                to: 200
                duration: 3000
                easing.type: Easing.OutCubic    //设置运动轨迹
            }
    
            NumberAnimation{
                id: animationRotation
                target: rect
                property: "rotation"
                to: 360
                duration: 3000
                running: false
                easing.type: Easing.OutInQuad
            }
    
            NumberAnimation on radius {
                id: animationRadius
                to: 25
                duration: 2000
                running: false
            }
        }
    }

    效果图如下:

    ColorAnimation类

    在来说说这个ColorAnimation类,巧了,也是前两个远亲的亲戚。它也就干了一件事,重写了from和to属性的类型。改成了color类型。无代码说个卵。。。mdzz,看我下面

    import QtQuick 2.2
    
    Rectangle{
        id: rootItem
         360
        height: 240
        color: "#EEEEEE"
    
        Rectangle{
            id: rect
             60
            height: 60
            anchors.centerIn: parent
            radius: 30
            color: "red"
    
            MouseArea{
                id: mouseArea
                anchors.fill: parent
                onClicked: ColorAnimation{
                    target: rect
                    property: "color"
                    to: "green"
                    duration: 1500
                }
            }
        }
    }

  • 相关阅读:
    B 合约数
    Weekly Contest 80
    第十六届上海大学程序设计联赛春季赛暨上海高校金马五校赛
    2018年长沙理工大学第十三届程序设计竞赛
    通过 DDNS 解决宽带拨号 ip 变化问题
    frp 内网穿透的使用 和原理
    笔记本centos 取消 关闭盖子自动挂起
    centos7 pptp 安装
    linux 命令收集
    centos7 关闭防护墙
  • 原文地址:https://www.cnblogs.com/SaveDictator/p/8127386.html
Copyright © 2011-2022 走看看