【问题标题】:Complex group animation in QtQuick 2.0QtQuick 2.0 中的复杂组动画
【发布时间】:2014-02-02 10:12:27
【问题描述】:

我试图将顶级“cont”矩形动画向右移动,缩小它,然后将其向右移动一点,然后在左滑动时将其向后移动到左侧。同时它也会缩小后面的矩形,它将缩放大小设置为屏幕的大小,并将矩形与屏幕右侧齐平。

谁能给我一些关于我需要怎么做的指示?

查看图片以了解我想要实现的目标

而且我忘了提到如何将缓动应用到动画中?


(来源:paisei.com


(来源:paisei.com

import QtQuick 2.0
import QtQuick.Controls 1.1

Item {
    id: root

    // default size, but scalable by user
    height: 450
    width: 300

    signal clickInit();

    MouseArea{

        anchors.fill: parent
        signal swipeRight;
        signal swipeLeft;
        signal swipeUp;
        signal swipeDown;

        property int startX;
        property int startY;

        onPressed: {
            startX = mouse.x;
            startY = mouse.y;
        }

        onReleased: {
            var deltax = mouse.x - startX;
            var deltay = mouse.y - startY;

            if (Math.abs(deltax) > 50 || Math.abs(deltay) > 50) {
                if (deltax > 30 && Math.abs(deltay) < 30) {
                    // swipe right
                    console.log("swiped right");
                    downSizeToRight.start()
                    swipeRight();
                } else if (deltax < -30 && Math.abs(deltay) < 30) {
                    console.log("swiped left")
                    // swipe left
                    upSizeFromRight.start()
                    swipeLeft()
                } else if (Math.abs(deltax) < 30 && deltay > 30) {
                    console.log("swiped down")
                    // swipe down
                    swipeDown()
                } else if (Math.abs(deltax) < 30 && deltay < 30) {
                    console.log("swiped up")
                    // swipe up
                    swipeUp()
                }
            }
        }

        Rectangle{
            id: bg
            gradient: Gradient {
                    GradientStop { position: 0.0; color: "#000000" }
                    GradientStop { position: 1.0; color: "#fff" }
                }
            height : cont.height + 80
            width : cont.width + 80
            y:cont.y - 40
            x: cont.x - 80

        }

        Rectangle{
            id: cont
            width:parent.width
            height:parent.height
            transform: Scale {
                        id: scaleTransform
                        property real scale: 1
                        xScale: scale
                        yScale: scale
                    }

            SequentialAnimation {
                id: downSizeToRight
                loops: 1
                PropertyAnimation {
                    target: scaleTransform
                    properties: "scale"
                    from: 1.0
                    to: 0.5
                    duration: 300
                }
            }

            SequentialAnimation {
                id: upSizeFromRight
                loops: 1
                PropertyAnimation {
                    target: scaleTransform
                    properties: "scale"
                    from: 0.5
                    to: 1.0
                    duration: 300
                }
            }

            Label {
                id: label1
                y: 226
                text: qsTr("Hi this is just a load of text that i cant write in that makes no sence for testing")
                horizontalAlignment: Text.AlignHCenter
                wrapMode: Text.WordWrap
                anchors.right: parent.right
                anchors.rightMargin: 5
                anchors.left: parent.left
                anchors.leftMargin: 5
            }
        }


    }
}

【问题讨论】:

  • 那么,你需要让2个动画同时工作吗?对不起,我不是很清楚你想做什么。你能再解释一下吗?对于缓动:只需在“PropertyAnimation”中设置easing.type 属性easing.type: Easing.InOutQuad。附:你的第一句话带来了一些误解。
  • 感谢您的回复。我刚看到你的评论。我已经修好了,但非常感谢。 Qt Quick 很棒。感谢您的帮助。
  • 也感谢您的好评。是的,qt quick 太棒了 :) 其他人知道你的解决方案会很好,所以你可以在这里写它并将其标记为已解决我想帮助其他人。但是,正如我之前所说 - 请详细描述您的问题。

标签: javascript qt animation swipe qtquick2


【解决方案1】:

对于有兴趣做这样的事情的人来说,这是我的解决方案,但我仍然有一个错误,我目前仍在尝试找到一个修复程序,该修复程序位于从前到左动画的比例尺上后矩形飞回左侧覆盖左后矩形。它有点难以描述,但如果你编译并左右滑动你会看到错误。

而且我是 qt quick 的初学者,所以如果您觉得有更好的方法可以在此代码中执行任何操作,那么任何更改都将不胜感激。

谢谢

import QtQuick 2.0

MouseArea {
    id:screen
    width: 320
    height: 460

    property int startX;property int startY
    signal swipeRight;signal swipeLeft;signal swipeUp;signal swipeDown

    property int size_addition:100
    property bool swiped: false
    property int swiped_direction:1
    property int aniSpeed: 200;

    states: [
        State {
            name: "frontToRight"
            PropertyChanges {target: front;x:(screen.width - (screen.width/3) + (screen.width/24) - 25)}
            PropertyChanges {target: front;scale:0.5}
            PropertyChanges {target: right;x:screen.width}
            PropertyChanges {target: left;scale:1}
        },
        State {
            name: "frontToLeft"
            PropertyChanges {target: front;x:-(screen.width - (screen.width/3) + (screen.width/24) - 25)}
            PropertyChanges {target: front;scale:0.5}
            PropertyChanges {target: right;scale:1}
        }
    ]

    onPressed: {startX=mouse.x;startY=mouse.y;}
    onReleased: {
        var swipe_a = 115; var deltax = mouse.x - startX; var deltay = mouse.y - startY
        if (Math.abs(deltax) > 100 || Math.abs(deltay) > 100) {
            if (deltax > swipe_a && Math.abs(deltay) < swipe_a) {swipeRight()}
            else if (deltax < -swipe_a && Math.abs(deltay) < swipe_a){swipeLeft()}
            else if (Math.abs(deltax) < swipe_a && deltay > swipe_a) {swipeDown()}
            else if (Math.abs(deltax) < swipe_a && deltay < swipe_a) {swipeUp()}
        }
    }

    onSwipeRight: {
        //scale to right
        if(front.height == screen.height && swiped_direction!=0 && swiped_direction!=2)
        {screen.state = "frontToRight";swiped = true;swiped_direction = 0;}
        //back to center from left
        else if(swiped && swiped_direction!=0)
        {screen.state = "";swiped = false;swiped_direction = 1;}
    }

    onSwipeLeft: {
        //scale to left // here is where my swipe problem lies 
        if(front.height == screen.height && swiped_direction!=2 && swiped_direction!=0)
        {screen.state = "frontToLeft";swiped = true;swiped_direction = 2;}
        //back to center from right
        else if(swiped && swiped_direction!=2)
        {screen.state = "";screen.swiped = false;screen.swiped_direction = 1;}
    }

    Rectangle{
        id:left
        color:"#0500ff"
        height:screen.height
        width:screen.width
        transformOrigin: Item.Right
        scale:1.2
        Behavior on scale{NumberAnimation{duration:aniSpeed}}
        Text{
            text:"Left"
            anchors.fill: parent
            font.pixelSize: 70
        }
    }

    Rectangle{
        id:right
        color:"#028000"
        height:screen.height
        width:screen.width
        transformOrigin: Item.Left
        Behavior on scale{NumberAnimation{duration:aniSpeed}}
        scale:1.2
        Text{
            text:"Right"
            anchors.fill: parent
            font.pixelSize: 70
        }
    }

    Rectangle{
        id:front
        color:"red"
        height:screen.height
        width:screen.width
        Behavior on scale{ NumberAnimation{duration:aniSpeed;}}
        Behavior on x{NumberAnimation{duration:aniSpeed}}
        Text{
            text:"Front"
            anchors.fill: parent
            font.pixelSize: 70
        }
    }
}

【讨论】:

    【解决方案2】:

    好的,伙计们。 我已经让它工作了,但它向我抱怨说 Qt Quick Designer 不支持命令式代码。

    import QtQuick 2.0
    import QtQuick.Controls 1.1
    import QtQuick.Controls.Styles 1.1
    MouseArea {
        id:screen
        width: 320
        height: 460
    
        property int startX;property int startY
        signal swipeRight;signal swipeLeft;signal swipeUp;signal swipeDown
    
        property int size_addition:100
        property bool swiped: false
        property int swiped_direction:1
        property int aniSpeed: 200;
    
        states: [
            State {
                name: "frontToRight"
                PropertyChanges {target: front;x:(screen.width - (screen.width/3) + (screen.width/24) - 25)}
                PropertyChanges {target: front;scale:0.5}
                //PropertyChanges {target: right;x:screen.width}
                PropertyChanges {target: left;scale:1}
            },
            State {
                name: "frontToLeft"
                PropertyChanges {target: front;x:-(screen.width - (screen.width/3) + (screen.width/24) - 25)}
                PropertyChanges {target: front;scale:0.5}
                PropertyChanges {target: right;scale:1}
            }
        ]
    
        onPressed: {startX=mouse.x;startY=mouse.y;}
        onReleased: {
            var swipe_a = 115; var deltax = mouse.x - startX; var deltay = mouse.y - startY
            if (Math.abs(deltax) > 100 || Math.abs(deltay) > 100) {
                if (deltax > swipe_a && Math.abs(deltay) < swipe_a) {swipeRight()}
                else if (deltax < -swipe_a && Math.abs(deltay) < swipe_a){swipeLeft()}
                else if (Math.abs(deltax) < swipe_a && deltay > swipe_a) {swipeDown()}
                else if (Math.abs(deltax) < swipe_a && deltay < swipe_a) {swipeUp()}
            }
        }
    

    我通过设置左侧面板的 z 属性来修复它。有没有更好的方法来做到这一点?我也尝试过放一些缓动来让动画看起来更好一点,但似乎没有什么看起来很好。有人有什么建议吗?

        onSwipeRight: {
            //scale to right
            if(front.height == screen.height && swiped_direction!=0 && swiped_direction!=2)
            {screen.state = "frontToRight";swiped = true;swiped_direction = 0;left.z=2}
            //back to center from left
            else if(swiped && swiped_direction!=0)
            {screen.state = "";swiped = false;swiped_direction = 1;}
        }
    
        onSwipeLeft: {
            //scale to left // here is where the righ tbg menu swipe problem lies
            if(front.height == screen.height && swiped_direction!=2 && swiped_direction!=0)
            {screen.state = "frontToLeft";swiped = true;swiped_direction = 2;left.z=0}
            //back to center from right
            else if(swiped && swiped_direction!=2)
            {screen.state = "";screen.swiped = false;screen.swiped_direction = 1;}
        }
    
        Rectangle{
            id:left
            color:"#0500ff"
            height:screen.height
            width:screen.width
            z:0
            transformOrigin: Item.Right
            scale:1.2
            Behavior on scale{NumberAnimation{duration:aniSpeed}}
            Text{
                text:"Left"
                anchors.fill: parent
                font.pixelSize: 70
            }
        }
    
        Rectangle{
            id:right
            z:1
            color:"#028000"
            height:screen.height
            width:screen.width
            transformOrigin: Item.Left
            Behavior on scale{NumberAnimation{duration:aniSpeed}}
            scale:1.2
            Text{
                text:"Right"
                anchors.fill: parent
                font.pixelSize: 70
            }
        }
    
        Rectangle{
            id:front
            color:"red"
            height:screen.height
            width:screen.width
            z:2
            Behavior on scale{ NumberAnimation{duration:aniSpeed;}}
            Behavior on x{NumberAnimation{duration:aniSpeed}}
            Text{
                text:"Front"
                anchors.fill: parent
                font.pixelSize: 70
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      我修复了我在使用此应用时遇到的一些其他问题。所以我重新启动了它,这是没有错误的新版本,并且运行良好。

      import QtQuick 2.0
      import QtQuick.Window 2.0
      import QtQuick.Controls 1.0
      
      GestureArea {
          id:main
          width: 470
          height: 700
          property int swiped_direction:1
          property bool swiped:false
          property int aniSpeed: 90
      
          onSwipeRight: {doRightSwipeProcess()}
          onSwipeLeft: {doLeftSwipeProcess()}
      
          states: [
              State {
                  name: "toLeft"
                  PropertyChanges {target: front;x:(main.width - (main.width/3) + (main.width/24) - 25)}
                  PropertyChanges {target: front;scale:0.5}
                  PropertyChanges {target: left;scale:1}
              },
              State {
                  name: "toRight"
                  PropertyChanges {target: front;x:-(main.width - (main.width/3) + (main.width/24) - 25)}
                  PropertyChanges {target: front;scale:0.5}
                  PropertyChanges {target: right;scale:1}
              }
          ]
      
          Rectangle{
              id:front
              width:main.width
              height:main.height
              property int direction:1
              color:"#fff"
              Behavior on scale{NumberAnimation{duration:aniSpeed;}}
              Behavior on x{NumberAnimation{duration:aniSpeed}}
              z:2
          }
      
          Image{
              id:left
              source:"images/app_bg_left.png"
              Behavior on scale{NumberAnimation{duration: main.aniSpeed}}
              width:main.width
              height:main.height
              transformOrigin: Item.Right
              scale:1.3
              anchors.right:{if(scale<1.3){return main.right}else{return main.left}}
              z:0
          }
      
          Settings{
              id:right
              //source:"images/app_bg_right.png"
              Behavior on scale{NumberAnimation{duration: main.aniSpeed}}
              width:main.width
              height:main.height
              transformOrigin: Item.Left
              scale:1.3
              anchors.left:{if(scale<1.3){return main.left}else{return main.right}}
              z:1
              onDoLeftSwipe: doLeftSwipeProcess()
              onDoRightSwipe: doRightSwipeProcess()
          }
      
      
          function doRightSwipeProcess(){
              //scale to right
              if(front.height == main.height && swiped_direction!=0 && swiped_direction!=2)
              {main.state = "toLeft";swiped = true;swiped_direction = 0;front.direction = 0}
              //back to center from left
              else if(swiped && swiped_direction!=0)
              {main.state = "";swiped = false;swiped_direction = 1;front.direction = 1;}
          }
      
          function doLeftSwipeProcess(){
              //scale to left // here is where the righ tbg menu swipe problem lies
              if(front.height == main.height && swiped_direction!=2 && swiped_direction!=0)
              {main.state = "toRight";swiped = true;swiped_direction = 2;front.direction = 2}
              //back to center from right
              else if(swiped && swiped_direction!=2)
              {main.state = "";main.swiped = false;main.swiped_direction = 1;front.direction = 1}
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-11-10
        • 2013-07-23
        • 2012-05-01
        • 1970-01-01
        • 2018-05-20
        • 1970-01-01
        • 2013-08-26
        • 1970-01-01
        相关资源
        最近更新 更多