【问题标题】:titanium animate label color钛动画标签颜色
【发布时间】:2016-03-20 09:36:08
【问题描述】:

请看以下代码 sn-p,在 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 秒内。

知道代码或其他东西可能有什么问题吗?

【问题讨论】:

    标签: animation appcelerator appcelerator-titanium


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我尝试了评论中的两个新代码示例,但没有一个给出动画期间的持续时间,它仍然立即发生......如果这些例子应该是不是有点混乱已经奏效了,想想为背景颜色设置动画效果对动画持续时间有效吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多