1

Titanium で Alloy MVC フレームワークを使用しており、ビュー間でスライドショーを作成したいと考えています。画面をスワイプすると、右から左または左から右へのスライド効果で次/前のビューを表示したい。私はこのコードを使用しています:

私の index.xml のタブ:

<Tab title="Bilan" icon="KS_nav_ui.png">
    <Window title="Bilan" id="bilanTab" onSwipe="doBilanSwipe">
    </Window>
</Tab>

動的に追加され、bilanTab 内に入力された質問ビュー:

<Alloy>
<Collection src="ReponsePossible">
<View id="questionContainer" class="container">
    <Label id="questionText" />
    <Button id="buttonNextQuestion">Question suivante</Button>
</View>
</Alloy>

そして、index.jsコントローラー内の私の2つの関数(prevQuestionがここに印刷されていない3つ):

var previousQuestion;
var nextQuestion;

function doBilanSwipe(e){
    if (e.direction == 'left'){
        nextQuestion();
    }
    else if (e.direction == 'right'){
        prevQuestion();
    }
}



function nextQuestion(){
    if (questionsCurrentIndex < questions.length-1){
        questionsCurrentIndex++;
        $.previous = previousQuestion;
        $.next = Alloy.createController('question', questions.at(questionsCurrentIndex));
        nextQuestion = $.next;
        $.next.questionContainer.left = 320;
        $.bilanTab.add($.next.questionContainer);
        $.next.questionContainer.animate({left:0, duration:200});
        $.previous.questionContainer.animate({left:-320, duration:200},function(){
            $.previous = previousQuestion;
            $.next = nextQuestion;
            $.bilanTab.remove($.previous.questionContainer);
            previousQuestion = $.next;
            $.previous.destroy();
        });
    }
}

私の問題は、最初のアニメーション (左に移動する最初のビュー) は問題ありませんが、その後、アニメーションなしで次のビューが表示されることです。

誰か助けてくれませんか?ありがとう!

4

1 に答える 1

6

Titanium.UI.ScrollableViewすべてのプラットフォームで、これとまったく同じことを行うが既に存在します。

次のように Alloy で使用します。

<Alloy>
    <Window id="win">
        <ScrollableView id="scrollableView" showPagingControl="true">
            <View id="view1" backgroundColor="#123" />
            <View id="view2" backgroundColor="#246" />
            <View id="view3" backgroundColor="#48b" />
        </ScrollableView>
    </Window>
</Alloy>

次のように、コントローラー内でビューを動的に追加できます。

$.scrollableView.addView(Ti.UI.createView({ // your custom attributes here});
于 2013-03-24T17:38:55.533 に答える