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);
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.