2016-04-17 44 views
0

我試圖重新調整代碼以創建自定義進度欄 - 但我無法理解如何進行最終更改。如何在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(); 

所以最終的綠色進度完成時 - 我想

一個。用「完成」替換「正在工作」
b。 1000 ms後 - 使整個進度條消失。

回答

1

無需添加監聽器的完整事件complete事件偵聽器,您可以在動畫的方法本身添加匿名函數

progress.animate({ 
    width: "100%", 
    duration: 1000 
},function(e){ 
    label1.text = "complete"; 
    win.remove(track); 
}); 
+0

真棒!謝謝..快速的問題 - 我可以在label1後添加一個500毫秒的等待嗎? – hypermails

+0

progress.animate({ 寬度: 「100%」, 持續時間:500 },函數(E){ label1.text = 「完成」; \t \t的setTimeout(函數(){ \t \t //請求方法這裏 \t \t win.remove(軌道); \t \t},5000); }); – hypermails

-1

您可以使用Animation object

// 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); 

更多細節Titanium.UI.Animation

+0

你好 - 我不確定這是如何工作的,並插入上面的代碼。對不起 - 我是新手,我不確定。 – hypermails

相關問題