2016-02-13 133 views
0

我想动画一个视图。从屏幕底部查看幻灯片动画到顶部

我希望视图从屏幕的底部滑动到顶部。

我写了这段代码,但是这个视图并没有显示出来。

myWin.add(myView); 
myView.height = '0%'; 
var expand= Ti.UI.createAnimation({ 
    height: '100%', 
    duration: 300 
}); 
myView.animate(expandView); 

参考是看这个document

回答

0

你应该叫动画的方法传递您所创建动画对象的引用。

myView.animate(expand); 
+0

谢谢@Mushood,但这是我的错字。我写了animate()而不是add()。问题可能在其他地方。 – whitebear

0

对于你的要求试试这个

var win = Ti.UI.createWindow({ backgroundColor : '#fff'}); 
var myView = Ti.UI.createView({backgroundColor : 'red'}); 
win.add(myView); 
myView.height = '0%'; 
myView.bottom = '0'; // basically the view has been added at bottom of window 

var expand= Ti.UI.createAnimation({ 
    height: '100%', 
    duration: 1300 
}); 
myView.animate(expand);// and you are only increasing the view's height in animate 
1

@whitebear。在你的问题中,你想让视图从底部滑到顶部,但是你采取了错误的方式。你采取的方式是一个形状改变动画,它想要更改高度的视图来做到这一点。但它永远不会得到滑动行动你想要的,如果你的代码工作,你会看到的是视图会得到越来越大,直到填满窗口,而不是滑动行动。

你想要的是一个位置更改动画为视图。只需更改顶部的值即可使其成为视图。例如:

var view = Ti.UI.createView({ 
    top: '-100%',    //the view can't be see at the bottom 
    width: '100%', 
    height: '100%', 
    backgroundColor: 'red' 
}); 

var ani = Ti.UI.createAnimation({ 
    top: 0,     //show the view from the bottom to top 
    duration: 3000 
}); 

view.animate(ani); 

只是有一个尝试,我希望这可以帮助你。如果你真的想改变视图的高度来获得效果,也许你可以定义一个方法来设置视图高度和时间。祝你好运!