我在Titanium上使用Alloy MVC框架,并希望在视图之间进行幻灯片放映.当我在屏幕上滑动时,我想显示下一个/上一个视图,其中包含从右到左或从左到右的滑动效果.我正在使用此代码:
我的index.xml中的一个标签:
<Tab title="Bilan" icon="KS_nav_ui.png">
<Window title="Bilan" id="bilanTab" onSwipe="doBilanSwipe">
</Window>
</Tab>
Run Code Online (Sandbox Code Playgroud)
在bilanTab中动态添加和填充问题视图:
<Alloy>
<Collection src="ReponsePossible">
<View id="questionContainer" class="container">
<Label id="questionText" />
<Button id="buttonNextQuestion">Question suivante</Button>
</View>
</Alloy>
Run Code Online (Sandbox Code Playgroud)
和index.js控制器里面的两个函数(在这里没有打印出来的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); …Run Code Online (Sandbox Code Playgroud)