pec1985 / TiDraggable

Native iOS and Android modules for Appcelerator's Titanium Mobile
74 stars 75 forks source link

Animate back to start position #6

Open iantearle opened 11 years ago

iantearle commented 11 years ago

Is it possible to have the view animate (elastic) to its start position? The most obvious example I guess is the new Facebook message heads animations.

\ EDIT: I have just seen in the screenr that your green and red boxes do this already, but I cannot seem to replicate it? I have even copied and pasted the example code. Mine just stick to where I drop them...

chrisribe commented 10 years ago

Hi,

Here is how I did it… Note the position reset workaround see my posted issue https://github.com/pec1985/TiDraggable/issues/14 for more details.

var someStartX = 10;
var someStartY = 10;
view.addEventListener('end', function(e)
{   
    //Position reset workaround….
    e.source.setLeft(e.source.left);
    e.source.setTop(e.source.top);

    var a= Ti.UI.createAnimation({top: someStartY, left: someStartX});
    e.source.animate(a);
});

Chris