钛动画标签颜色

时间:2016-03-20 09:36:09

标签: animation appcelerator appcelerator-titanium

请参阅以下代码段,在Appcelerator Studio SDK 5.2.0.GA中进行了测试:

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

代码创建一个窗口,其中包含一个视图和一个标签。

一次一个地测试具有动画的4行(即,测试,一次取消注释一行)。第一个在1秒内激活窗口的背景颜色。工作正常。第二个动画显示视图的背景颜色,工作正常。第三个动画标签的背景颜色,工作正常。第四个用于为标签文本颜色设置动画。这不会像人们期望的那样起作用。动画发生,但它立即发生,而不是在1秒内发生。

对代码或其他什么可能出错的任何想法?

1 个答案:

答案 0 :(得分:2)

也许你没有看到动画,因为它是在打开窗口后调用的。尝试添加setTimeout:

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

或者,在窗口postlayout事件后执行动画:https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-event-postlayout

win0.addEventListener('postlayout', function(e){
  label0.animate({color:"blue", duration: 1000});
});
相关问题