在QtQuick 2.0复杂的群体动画 [英] Complex group animation in QtQuick 2.0

查看:204
本文介绍了在QtQuick 2.0复杂的群体动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去顶层续矩形动画的权利,下限它,将其移到右一点点,后面留在左侧刷卡。在同一时间,将向下尺度背面矩形也,它将规模大小设置为屏幕和将矩形平齐放置到屏幕的右侧。

会有人强麦给我如何我需要做它的一些指针?

请参考图片我想要实现

和我忘了说我如何将适用回落至动画呢?


 进口QtQuick 2.0
进口QtQuick.Controls 1.1项{
    ID:根    //默认大小,而是通过用户的可扩展性
    身高:450
    宽度:300    信号clickInit();    鼠标区域{        anchors.fill:父
        信号swipeRight;
        信号swipeLeft;
        信号swipeUp;
        信号swipeDown;        物业INT startx的;
        物业INT startY;        在pressed:{
            运行startx = mouse.x;
            startY = mouse.y;
        }        onReleased:{
            VAR DELTAX = mouse.x - startx的;
            VAR DELTAY = mouse.y - startY;            如果(Math.abs(DELTAX)→50 || Math.abs(DELTAY)→50){
                如果(DELTAX→30&放大器;&放大器; Math.abs(DELTAY)小于30){
                    //右轻扫
                    的console.log(刷卡权);
                    downSizeToRight.start()
                    swipeRight();
                }否则如果(DELTAX&所述; -30&放大器;&放大器; Math.abs(DELTAY)小于30){
                    的console.log(刷卡左)
                    //向左轻扫
                    upSizeFromRight.start()
                    swipeLeft()
                }否则如果(Math.abs(DELTAX)小于30&放大器;&放大器; DELTAY大于30){
                    的console.log(刷下来)
                    // 刷下
                    刷下()
                }否则如果(Math.abs(DELTAX)小于30&放大器;&放大器; DELTAY小于30){
                    的console.log(刷卡达)
                    //向上轻扫
                    swipeUp()
                }
            }
        }        长方形{
            ID:BG
            渐变:渐变{
                    渐变停止{位置:0.0;颜色:#000000}
                    渐变停止{位置:1.0;颜色:#FFF}
                }
            高度:cont.height + 80
            宽度:cont.width + 80
            Y:cont.y - 40
            X:cont.x - 80        }        长方形{
            ID:续
            宽度:parent.width
            高度:parent.height
            变换:规模{
                        ID:scaleTransform
                        财产真实比例:1
                        xScale等:规模
                        yScale:规模
                    }            SequentialAnimation {
                ID:downSizeToRight
                循环:1
                PropertyAnimation {
                    目标:scaleTransform
                    属性:规模
                    来自:1.0
                    于:0.5
                    持续时间:300
                }
            }            SequentialAnimation {
                ID:upSizeFromRight
                循环:1
                PropertyAnimation {
                    目标:scaleTransform
                    属性:规模
                    来自:0.5
                    于:1.0
                    持续时间:300
                }
            }            标签 {
                ID:卷标
                Y:226
                文本:QSTR(这只是一个,我不能在写文字的负载不作任何SENCE测试)
                的Horizo​​ntalAlignment:Text.AlignHCenter
                wrapMode:Text.WordWrap
                anchors.right:parent.right
                anchors.rightMargin:5
                anchors.left:parent.left
                anchors.leftMargin:5
            }
        }
    }
}


解决方案

我固定的,我是用这个程序有一些其他问题。所以我重新启动它,这是新版本没有任何错误和非常漂亮的作品。

 进口QtQuick 2.0
进口QtQuick.Window 2.0
进口QtQuick.Controls 1.0GestureArea {
    ID:主
    宽度:470
    身高:700
    物业INT swiped_direction:1
    物业布尔刷卡:假的
    物业INT aniSpeed​​:90    onSwipeRight:{doRightSwipeProcess()}
    onSwipeLeft:{doLeftSwipeProcess()}    状态: [
        国{
            名称:toLeft
            PropertyChanges {目标:前; X:(main.width - (main.width / 3)+(main.width / 24) - 25)}
            PropertyChanges {目标:前;规模:0.5}
            PropertyChanges {目标:离开;规模:1}
        },
        国{
            名称:toRight
            PropertyChanges {目标:前; X :-( main.width - (main.width / 3)+(main.width / 24) - 25)}
            PropertyChanges {目标:前;规模:0.5}
            PropertyChanges {目标:权利;规模:1}
        }
    ]    长方形{
        ID:前
        宽度:main.width
        高度:main.height
        物业INT方向:1
        颜色:#FFF
        上规模的行为{{NumberAnimation时间:aniSpeed​​;}}
        在X行为{{NumberAnimation时间:aniSpeed​​}}
        Z:2
    }    图片{
        ID:左
        来源:图像/ app_bg_left.png
        上规模的行为{{NumberAnimation时间:main.aniSpeed​​}}
        宽度:main.width
        高度:main.height
        transformOrigin:Item.Right
        规模:1.3
        anchors.right:{如果(规模< 1.3){返回main.right}其他{回报main.left}}
        Z:0
    }    设置{
        ID:右
        //source:\"images/app_bg_right.png
        上规模的行为{{NumberAnimation时间:main.aniSpeed​​}}
        宽度:main.width
        高度:main.height
        transformOrigin:Item.Left
        规模:1.3
        anchors.left:{如果(规模< 1.3){返回main.left}其他{回报main.right}}
        Z:1
        onDoLeftSwipe:doLeftSwipeProcess()
        onDoRightSwipe:doRightSwipeProcess()
    }
    功能doRightSwipeProcess(){
        //规模向右
        如果(front.height == main.height&放大器;&安培; swiped_direction = 0&安培;!&安培; swiped_direction = 2!)
        {main.state =toLeft;刷卡= TRUE; swiped_direction = 0; front.direction = 0}
        //回到左中心
        否则如果(刷卡&放大器;&放大器;!swiped_direction = 0)
        {main.state =;刷卡= FALSE; swiped_direction = 1; front.direction = 1;}
    }    功能doLeftSwipeProcess(){
        //规模//在这里留下的是右击菜单TBG刷卡问题出在哪里
        如果(front.height == main.height&放大器;&放大器; swiped_direction = 2及!&放大器; swiped_direction!= 0)
        {main.state =toRight;刷卡= TRUE; swiped_direction = 2; front.direction = 2}
        //回到右中心
        否则如果(刷卡&放大器;&放大器;!swiped_direction = 2)
        {main.state =; main.swiped = FALSE; main.swiped_direction = 1; front.direction = 1}
    }
}

Im trying to animate the top level "cont" rectangle to the right, downscale it, and move it over the right a little bit and the back to left on left swipe. At the same time it will down scale the back rectangle also, It will set the scale size to that of the screen and will place the rectangle flush to the right of the screen.

Would anyone be ale to give me some pointers on how I need to do it?

Check pictures for reference to what I'm trying to achieve

And I forgot to mention how would I apply easing to the animation as well?

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
            }
        }


    }
}

解决方案

I fixed some other issues that I was having with this app. So I restarted it and this is the new version with no errors and works very nicely.

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}
    }
}

这篇关于在QtQuick 2.0复杂的群体动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆