我刚刚使用Appcelerator Titanium创建了一个滑出控件。
我做了什么:
我在视图上添加了一个按钮,并将其添加到窗口中。
// Create a Button.
var Animate = Ti.UI.createButton({
title : 'Animate',
height : 'auto',
width : 'auto',
top : 'auto',
left : 'auto'
});
// Listen for click events.
Animate.addEventListener('click', function() {
var matrix = Ti.UI.create2DMatrix();
if(flag) //Initially the flag is set to true
{
matrix = matrix.translate(100,0);
}
else
{
matrix = matrix.translate(0,0);
}
flag = !flag;
var a = Ti.UI.createAnimation({
transform : matrix,
duration : 1000,
//autoreverse : true,
//repeat : 3
});
self.animate(a);
});
// Add to the parent view.
self.add(Animate); //Here self is my view
预期输出
实际输出:
初始屏幕
当我点击按钮时,滑出:
当我点击重置时,会发生问题:
答案 0 :(得分:1)
我尝试了很多方法,但没有任何帮助。 最后我做了以下工作,并且有效。
不是向视图添加动画,而是将其添加到窗口并稍微更改了代码。
var firstView = new FirstView();
self.add(firstView);
var xy = 0;
// Create a Button.
var Animate = Ti.UI.createButton({
title : 'Animate',
height : 100,
width : 100,
top : 0,
left : 0
});
// Listen for click events.
Animate.addEventListener('click', function() {
var xy = 0;
var matrix = Ti.UI.create2DMatrix();
if(flag)
{
xy = 100;
matrix = matrix.translate(100,0);
}
else
{
xy = 0;
matrix = matrix.translate(0,0);
}
flag = !flag;
var a = Ti.UI.createAnimation({
duration : 1000,
left:xy
});
a.addEventListener('complete',function()
{
firstView.left = 0;
});
self.animate(a); //self is the parent window
});
// Add to the parent
firstView.add(Animate);
答案 1 :(得分:0)
这可能是一个错误,但我确实知道使用auto
进行大小调整已被弃用或至少不推荐使用,我确信在进行转换时更不推荐使用它。
'auto'指定视图应选择FILL或SIZE行为。在2.0中,“auto”值的行为由UI Composite Layout Spec指定。建议不要将此值用于新开发,将来不推荐使用。 在Mobile Web和Tizen上,'auto'始终选择SIZE行为。
此外,auto不是top
和left
位置参数的有效条目。为什么不尝试:
// Create a Button.
var Animate = Ti.UI.createButton({
title : 'Animate',
height : Ti.UI.SIZE,
width : Ti.UI.SIZE,
top : 0,
left : 0
});
但正如我所说,这可能是一个错误。