2

私は Titanium を使用しており、iOS7 でエミュレータを実行しています。めくりアニメーションのようなカードを手に入れようとしています。私はそれが半分働いています。現在は からfrontback切り替わりますが、もう一度クリックするとすぐにアプリがクラッシュし、コンソールに何も表示されません。

ドキュメントは言う:

The new view being transitioned to should NOT be a child of another view or of the animating view.

私はこの仕事をすることができないように見えるので、間違っていることを理解しているのかもしれません。これまでの私のコードは次のとおりです。

var win = Ti.UI.currentWindow;
var noThumbColors   = ['#555555','#cccccc'];
var noThumbColors2  = ['#ff0000','#000'];

var views   = [];
var fronts  = [];
var backs   = [];
for (var i = 0; i < 1; i++)
{   
    fronts[i] = Ti.UI.createView({
        id:i,
        name:"front",
        width:150,
        height:150,
        backgroundGradient:{
            type: 'linear',
            startPoint: { x: '0%', y: '0%' },
            endPoint: { x: '0%', y: '100%' },
            colors: [ { color: noThumbColors[0], offset: 0.0}, { color: noThumbColors[1], offset: 1.0 } ],
        },
        currentAngle: 10
    });

    backs[i] = Ti.UI.createView({
        id:i,
        name:"back",
        width:150,
        height:150,
        backgroundGradient:{
            type: 'linear',
            startPoint: { x: '0%', y: '0%' },
            endPoint: { x: '0%', y: '100%' },
            colors: [ { color: noThumbColors2[1], offset: 0.0}, { color: noThumbColors2[0], offset: 1.0 } ],
        },
        currentAngle: 10
    });
    win.add(backs[i]);
    win.add(fronts[i]);
    fronts[i].addEventListener('click', function(e)
    {
        log(e.source.name);
        t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT;
        e.source.animate({view:backs[e.source.id],transition:t});

    });

    backs[i].addEventListener('click', function(e)
    {
        log(e.source.name);
        t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT;
        e.source.animate({view:fronts[e.source.id],transition:t});
    });
}

function log(msg)
{
    Ti.API.info(msg);
}

完成した作業コード (独立して前後に反転する 3 つの正方形が生成されます):

var win = Ti.UI.currentWindow;
var noThumbColors   = ['#555555','#cccccc'];
var noThumbColors2  = ['#ff0000','#000'];
var containers  = [];
var fronts      = [];
var backs       = [];

for (var i = 0; i < 3; i++)
{   
    containers[i] = Ti.UI.createView({
        top:50 + (i * 155),
        width:150,
        height:150
    });

    fronts[i] = Ti.UI.createView({
        id:i,
        name:"front",
        width:150,
        height:150,
        backgroundGradient:{
            type: 'linear',
            startPoint: { x: '0%', y: '0%' },
            endPoint: { x: '0%', y: '100%' },
            colors: [ { color: noThumbColors[0], offset: 0.0}, { color: noThumbColors[1], offset: 1.0 } ],
        },
        currentAngle: 10
    });

    backs[i] = Ti.UI.createView({
        id:i,
        name:"back",
        width:150,
        height:150,
        backgroundGradient:{
            type: 'linear',
            startPoint: { x: '0%', y: '0%' },
            endPoint: { x: '0%', y: '100%' },
            colors: [ { color: noThumbColors2[1], offset: 0.0}, { color: noThumbColors2[0], offset: 1.0 } ],
        },
        currentAngle: 10
    });
    containers[i].add(backs[i]);
    containers[i].add(fronts[i]);
    win.add(containers[i]);
}

win.addEventListener('click', function(e)
{
    if (e.source.name === "front")
    {
        containers[e.source.id].animate({view:backs[e.source.id],transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
    }
    else if (e.source.name === "back")
    {
        containers[e.source.id].animate({view:fronts[e.source.id],transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT});
    }
});

function log(msg)
{
    Ti.API.info(msg);
}
4

2 に答える 2

1

ウィンドウのようなカードをめくる簡単な方法は次のとおりです。

次のようにウィンドウのプロパティを設定する必要があります。

 var win = Ti.UI.currentWindow({
   height:'auto',
   width:'auto,'
   modal:true    
   });

 win.open({
    modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
    modalStyle: Ti.UI.iPhone.MODAL_PRESENTATION_FORMSHEET
 });

それが役立つことを願っています。

于 2013-11-12T11:31:24.200 に答える