qml 过渡 动画 转换

过渡:
transitions : list Transition
用于为状态变化添加动画,常与state配套使用,使用from和to来筛选state

  Rectangle {
      id: rect
      width: 100; height: 100
      states: State {
          name: "state1"
          PropertyChanges { target: rect; x: 0 }
      }
      states: State {
          name: "state2"
          PropertyChanges { target: rect; x: 50 }
      }

      transitions: Transition {
      	  from:"state1" to:"state2"
          PropertyAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }
      }
  }

动画:有两种使用方法:
方法一:使用Behavior on x 监听x的变化从而调用动画运行

  Rectangle {
      width: 100; height: 100
      color: "red"
      Behavior on x { PropertyAnimation {} }
      MouseArea { anchors.fill: parent; onClicked: parent.x = 50 }
  }

方法二:通过动画的id,使用start或running启动动画

Rectangle {
      id: theRect
      width: 100; height: 100
      color: "red"
      // this is a standalone animation, it's not running by default
      PropertyAnimation { id: animation;
                          target: theRect;
                          property: "width";
                          to: 30;
                          duration: 500 }
      MouseArea { anchors.fill: parent; onClicked: animation.running = true }
  }

转换:Item自带的属性,
transform : list Transform
常用于复杂的Scale和rotate变换,Transform可以是以下4种
在这里插入图片描述
变换时为了更好看,可与动画搭配使用。

Rectangle {
        id:rect
        width: 100; height: 100
        color: "blue"
        rotation:30
        property bool flip
        transform: Rotation { origin.x: 0; origin.y: 100;
            axis.x:1;axis.y:0;axis.z:0; angle:rect.flip?0:360
            Behavior on angle{
                NumberAnimation{
                    duration: 3000
                }
            }
        }
        MouseArea{
            anchors.fill:parent
            onClicked: rect.flip=!rect.flip
        }
        }
    }
  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值