Implementing Swipe guestures using Titanium sdk

You must Login before you can answer or comment on any questions.

Hi I am new to Titanium. I want to implement UISwipeGestureRecognizer using Titanium. Using this i want give page curlup and down animations.

Is it possible using Titanium? Please help me. Thanks in advaance.

2 Answers

Accepted Answer

var win=Titanium.UI.createWindow({

title:'Tab 1',
backgroundColor:'#fff',
orientationModes:[Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]

});

var view1 = Ti.UI.createView({

backgroundColor : 'red',
borderRadius : 10,
width : 1030,
height : 640,
top : 0,

});

var view2 = Ti.UI.createView({

backgroundColor : 'blue',
borderRadius : 10,
width : 1030,
height : 640,
top : 0,

});

var view3 = Ti.UI.createView({

backgroundColor : 'green',
borderRadius : 10,
width : 1030,
height : 640,
top : 0,

});

var view4 = Ti.UI.createView({

backgroundColor : 'pink',
borderRadius : 10,
width : 1030,
height : 640,
top : 0,

}); view_array = [view1, view2, view3,view4];

for(var view in view_array) {

win.add(view_array[view]);

}

var currentViewIndex = 0;

var showView = function(viewIndex) {

for(var view in view_array) {

    view_array[view].hide();

}

view_array[viewIndex].show()

win.animate({view:view_array[viewIndex],transition:Ti.UI.iPhone.AnimationStyle.CURL_UP});

}

var funcRef_forward = function() {

currentViewIndex++;
showView(currentViewIndex);

}

var funcRef_back = function() {

currentViewIndex--;
showView(currentViewIndex);

}

showView(0);

view1.addEventListener('touchstart',function(e){ x = e.x; });

view1.addEventListener('touchend',function(e){

              x=x - e.x;
              if(x<-20){ 
                if(currentViewIndex!=0){

                    currentViewIndex=currentViewIndex-1;
                    showView(currentViewIndex);

} } else if(x>20 && currentViewIndex<3){

                    currentViewIndex=currentViewIndex+1;
                    showView(currentViewIndex);
                    //addbutton();
             }
        });

view2.addEventListener('touchstart',function(e){ x = e.x; });

view2.addEventListener('touchend',function(e){

              x=x - e.x;
              if(x&lt;-20){ 
                if(currentViewIndex!=0){
                    currentViewIndex=currentViewIndex-1;
                    showView(currentViewIndex);
                     //addbutton();
                }
             }
             else if(x&gt;20 &amp;&amp; currentViewIndex&lt;3){

                    currentViewIndex=currentViewIndex+1;
                    showView(currentViewIndex);
                    //addbutton();
             }
        });

view3.addEventListener('touchstart',function(e){ x = e.x; });

view3.addEventListener('touchend',function(e){

              x=x - e.x;
              if(x&lt;-20){ 

if(currentViewIndex!=0){ currentViewIndex=currentViewIndex-1; showView(currentViewIndex); } }

             else if(x&gt;20 &amp;&amp; currentViewIndex&lt;3){

                    currentViewIndex=currentViewIndex+1;
                    showView(currentViewIndex);

             }
        });

view4.addEventListener('touchstart',function(e){

                x = e.x;

});

view4.addEventListener('touchend',function(e){

              x=x - e.x;
              if(x&lt;-20){ 
                if(currentViewIndex!=0){
                    currentViewIndex=currentViewIndex-1;
                    showView(currentViewIndex);
                }
             }

else if(x>20 && currentViewIndex<3){

                    currentViewIndex=currentViewIndex+1;
                    showView(currentViewIndex);

             }

});

win.open();

— answered 1 year ago by Moiz Chhatriwala
answer permalink
6 Comments
  • Try this code in IOS using Titanium 1.7.5 sdk You will Exactly see same behaviour what you are expecting

    Thanks

    Moiz

    — commented 1 year ago by Moiz Chhatriwala

  • Seems like my code Moiz . I waited for your so called help .

    — commented 1 year ago by mathew orleans

  • hi mathew , I gave reply to you ...I didn't got your response in return.

    — commented 1 year ago by Moiz Chhatriwala

  • Show 3 more comments

Hi, Ti views listen for the swipe event so you can hook into that. On IOS you can use the Titanium.UI.iPhone.AnimationStyle.CURL_UP animation to create that effect when opening windows

Your Answer

Think you can help? Login to answer this question!