Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Need to move view by increments using swipe - NOT working

Trying to move a view with a swipe but it only works the first time. I would like to move the view in increments by 50 either LEFT or RIGHT on each swipe.


w = Titanium.UI.currentWindow;

gallery = Titanium.UI.createView({
   backgroundColor:'red',
   width:50,
   height:50,
   left:100
});

w.addEventListener('swipe', function(e)
{
    if (e.direction == 'left'){
        gallery.animate({left: (gallery.left-50), duration: 500});
    }
    if (e.direction == 'right'){
        gallery.animate({right: (gallery.left+50), duration: 500});
    }
});
w.add(gallery);
— asked August 27th 2010 by Peter Levin
  • animate
  • swipe
  • view
0 Comments

1 Answer

  • I know this is extremely old but I am going to answer this just in case someone else runs into the problem.

    First off it is not a problem at all. by animating something it does NOT mean that you are changing the left value, you are only animating the view. You have to set the left value after animation and then it will work.

    w = Titanium.UI.currentWindow;
    
    gallery = Titanium.UI.createView({
       backgroundColor:'red',
       width:50,
       height:50,
       left:100
    });
    
    w.addEventListener('swipe', function(e)
    {
        if (e.direction == 'left'){
            gallery.animate({left: (gallery.left-50), duration: 500});
            gallery.left = gallery.left - 50;
        }
        if (e.direction == 'right'){
            gallery.animate({right: (gallery.left+50), duration: 500});
            gallery.left = gallery.left + 50;
        }
    });
    w.add(gallery);
    

    Hope this helps some that finds this a problem.

    — answered August 12th 2012 by Justin Greer
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.