Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created April 27, 2014 12:31
Show Gist options
  • Save nazrdogan/11344431 to your computer and use it in GitHub Desktop.
Save nazrdogan/11344431 to your computer and use it in GitHub Desktop.
Drag and Drop Titanium Mobile
var Win=Ti.UI.createWindow({
backgroundColor:'white'
});
var circle = Titanium.UI.createView({
height:200,
width:200,
backgroundColor:'#336699',
top:10,
left:50
});
Win.add(circle);
var circlePosition = { top: circle.top, left: circle.left };
var xxx = 0;
var yyy = 0;
circle.addEventListener('touchstart', function(e) {
xxx = e.x;
yyy = e.y;
});
circle.addEventListener('touchmove', function(e) {
circlePosition.top += e.y - yyy;
circlePosition.left += e.x - xxx;
Ti.API.info("Top-----"+circlePosition.top);
Ti.API.info("Left"+circlePosition.left);
circle.animate({
top: circlePosition.top,
left: circlePosition.left,
duration: 1
});
});
circle.addEventListener('touchend', function(e) {
xxx = 0;
yyy = 0;
});
Win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment