如何在 Appcelerator Titanium 中的事件后创建事件
how to create an event after an event in Appcelerator Titanium
我正在尝试重新调整代码的用途以创建自定义进度条 - 但我无法理解如何进行最终更改。
当前的实现没有进度条。我想要的是进度条更新文本然后自行消失。
var win = Ti.UI.createWindow({
backgroundColor: 'white',
});
var label1 = Ti.UI.createLabel({
text: 'Working on it...',
textAlign:'center',
});
var track = Ti.UI.createView({
width: "60%", height: "20%",
borderRadius:40,
backgroundColor: 'red'
});
var progress = Ti.UI.createView({
borderRadius:40,
left: 0,
width: 5, height: "100%",
backgroundColor : "green"
});
track.add(progress);
track.add(label1);
win.add(track);
win.addEventListener('open', function () {
progress.animate({
width: "100%",
duration: 1000
});
});
win.open();
所以当最后的绿色进度完成时 - 我想
一个。将 "working on it" 替换为 "complete"
b. 1000 毫秒后 - 使整个进度条消失。
您可以使用 Animation object
的 complete
事件侦听器
// create the animation
var animation = Ti.UI.createAnimation({
width: "100%",
duration: 1000
});
animation.addEventListener("complete", function onAnimationComplete(e){
// YOUR CODE HERE
animation.removeEventListener("complete", onAnimationComplete);
});
progress.animate(animation);
complete事件无需添加Listener,可以在animate方法本身添加匿名函数
例如
progress.animate({
width: "100%",
duration: 1000
},function(e){
label1.text = "complete";
win.remove(track);
});
我正在尝试重新调整代码的用途以创建自定义进度条 - 但我无法理解如何进行最终更改。
当前的实现没有进度条。我想要的是进度条更新文本然后自行消失。
var win = Ti.UI.createWindow({
backgroundColor: 'white',
});
var label1 = Ti.UI.createLabel({
text: 'Working on it...',
textAlign:'center',
});
var track = Ti.UI.createView({
width: "60%", height: "20%",
borderRadius:40,
backgroundColor: 'red'
});
var progress = Ti.UI.createView({
borderRadius:40,
left: 0,
width: 5, height: "100%",
backgroundColor : "green"
});
track.add(progress);
track.add(label1);
win.add(track);
win.addEventListener('open', function () {
progress.animate({
width: "100%",
duration: 1000
});
});
win.open();
所以当最后的绿色进度完成时 - 我想
一个。将 "working on it" 替换为 "complete"
b. 1000 毫秒后 - 使整个进度条消失。
您可以使用 Animation object
complete
事件侦听器
// create the animation
var animation = Ti.UI.createAnimation({
width: "100%",
duration: 1000
});
animation.addEventListener("complete", function onAnimationComplete(e){
// YOUR CODE HERE
animation.removeEventListener("complete", onAnimationComplete);
});
progress.animate(animation);
complete事件无需添加Listener,可以在animate方法本身添加匿名函数
例如
progress.animate({
width: "100%",
duration: 1000
},function(e){
label1.text = "complete";
win.remove(track);
});