2016-03-20 13 views
0

Bitte beachten Sie den folgenden Code-Schnipsel, getestet in Appcelerator Studio SDK 5.2.0.GA:Titan belebtes Etikettenfarbe

// 
// create base UI tab and root window 
// 
var win0 = Titanium.UI.createWindow({ 
    title:'Tab 1', 
    backgroundColor:'#fff' 
}); 

var label0 = Titanium.UI.createLabel({ 
    color:'red', 
    text:'I am Window 1', 
    font:{fontSize:20,fontFamily:'Helvetica Neue'}, 
    textAlign:'center', 
    width:'auto' 
}); 

view0 = Titanium.UI.createView({ 
borderRadius:10 
,width: 350 
,height:40 
,opacity:1 
,color:"blue" 
}); 

view0.add(label0); 

win0.add(view0); 

win0.open(); 

// Working 
//win0.animate({backgroundColor:"blue", duration: 1000}); 

// Working 
//view0.animate({backgroundColor:"blue", duration: 1000}); 

// Working 
//label0.animate({backgroundColor:"blue", duration: 1000}); 

// "Working", but there is no duration (animation takes place right away) 
label0.animate({color:"blue", duration: 1000}); 

// "Working", but there is no duration (animation takes place right away after the timer 5 sec timeout) 
//setTimeout(function(){ 
// label0.animate({color:"blue", duration: 1000}); 
//},5000); 

// If win0.open is placed before the code below, there is no animation at all. 
// If win0.open is placed after the code below, there is animation, but it takes place right away. 
//win0.addEventListener('postlayout', function(e){ 
// label0.animate({color:"blue", duration: 1000}); 
//}); 

Der Code erstellt ein Fenster mit einer Ansicht und ein Etikett Innenansicht.

Die 4 Zeilen mit Animation werden nacheinander getestet (d. H., Um einen Kommentar einzeln zu testen). Der erste animiert die Hintergrundfarbe des Fensters während 1 Sekunde. Funktioniert ok. Der zweite animiert die Hintergrundfarbe der Ansicht, funktioniert ok. Der dritte animiert die Hintergrundfarbe des Labels, funktioniert ok. Und der vierte soll die Etiketttextfarbe animieren. Dies funktioniert nicht wie erwartet. Die Animation findet statt, aber sie findet sofort statt, nicht während 1 Sekunde.

Irgendeine Idee, was könnte mit Code oder etwas anderes falsch sein?

Antwort

2

Vielleicht sehen Sie die Animation nicht, weil es nur nach dem Öffnen des Fensters aufgerufen wird. Versuchen Sie, eine SetTimeout hinzuzufügen:

setTimeout(function(){ 
    label0.animate({color:"blue", duration: 1000}); 
},5000); 

oder machen Sie Ihre Animation nach dem Fenster postlayout Ereignis: https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-event-postlayout

win0.addEventListener('postlayout', function(e){ 
    label0.animate({color:"blue", duration: 1000}); 
}); 
+0

ich die beiden neuen Codebeispiele aus dem Kommentar versucht, aber keiner von ihnen gab die Dauer während die Animation, sie hat immer noch sofort stattgefunden ... Ist es nicht ein bisschen verwirrend, wenn diese Beispiele hätten funktionieren sollen, daran zu denken, dass das Animieren der Hintergrundfarbe mit der Animationsdauer funktioniert? – blaffen