Search code examples
titanium

How to make slide animation for titanium


I have one window and one view and this view cover the 76% of the screen.

var win = Ti.UI.createWindow({
    backgroundColor: 'white',
    navBarHidden: true,
});

var view = Ti.UI.createView({
    backgroundColor:backgroundColor , 
    width:'76%',right:0,left:'24%',
    height:'100%'
});

win.addEventListener('click',function(e){
    win.add(view);
});

What I want to do is sliding the view from right slide of the screen. How do I do this? I guess I should use animate method though ,,,, Does anyone have sample source or something??


Solution

  • To animate something, you will indeed need to use the animate method. Here is an example for you:

    var view = Ti.UI.createView({
        backgroundColor:'yellow',
        width:'76%',
        right:-Ti.Platform.displayCaps.getPlatformWidth(),
        onScreen:false
    });
    win.tiview.add(view);
    
    win.tiview.addEventListener('click',function(e){
        var viewShowAnimation = Ti.UI.createAnimation({
           duration:250,
           right:0
        });
        var viewHideAnimation = Ti.UI.createAnimation({
           duration:250,
           right:-Ti.Platform.displayCaps.getPlatformWidth()
        });
        if(view.onScreen){
           view.animate(viewShowAnimation);
        }else{
           view.animate(viewHideAnimation);
        }
        view.onScreen = !view.onScreen;
    });