kra*_*kax 1 animation view titanium appcelerator titanium-alloy
我在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);
previousQuestion = $.next;
$.previous.destroy();
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是第一个动画(第一个视图向左移动)是好的,但在那之后,下一个视图只显示没有任何动画.
有人可以帮忙吗?谢谢!
Titanium.UI.ScrollableView对于所有平台,已经有了这个确切的事情.
像这样在合金中使用它:
<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>
Run Code Online (Sandbox Code Playgroud)
您可以在控制器内动态添加视图,如下所示:
$.scrollableView.addView(Ti.UI.createView({ // your custom attributes here});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4707 次 |
| 最近记录: |