我正在使用Titanium iphone中的Table视图。 我试图为每一行添加动画样式。
也就是说,当用户点击每一行时,行高需要增加,所以我能够在行中显示隐藏的内容。当用户再次点击时,行高需要减少。
我的代码是, 对于折叠视图,
var animation = Ti.UI.createAnimation({height: 1, duration: 500});
row.animate(animation);
和扩展视图,
row.animate(Ti.UI.createAnimation({ height:200, duration:300 });
但是上面两个代码都不起作用,
如果我在不使用动画的情况下设置行高,那么它的工作正常。 如何为表视图行应用动画样式... 任何人都可以。
答案 0 :(得分:4)
你可以试试这个
http://developer.appcelerator.com/question/119198/animating-row-height-changes
TableViewRow无法设置动画。这是文档错误。你需要制作自己的动画功能(即setTimeout)。
答案 1 :(得分:0)
默认情况下(在iOS上)更改行的高度时会更改它,因此:
row.height = '40dp';
答案 2 :(得分:0)
如果将行高直接设置为数值,则默认情况下会在iOS上对其进行动画处理。默认动画将覆盖您可能提出的任何自定义动画,例如使用标准setTimeout
javascript函数。
难点在于使行内容也显示为动画。让我们说row.details
指向容器视图,该容器视图包含要在扩展时显示的隐藏行详细信息。它的高度最初将设置为零。下面的代码将以平滑的方式为整行设置动画:
var total_height_increase = 260;
var height_step = 5;
var duration = 200;
var time_step = duration * height_step / total_height_increase;
var num_steps = duration / time_step;
var i=0;
var increase_height = function(){
setTimeout(function(){
row.details.height += height_step;
i += 1;
if (i > num_steps) return;
increase_height();
}, time_step);
};
increase_height();
row.height += total_height_increase;