Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created January 31, 2013 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanestillwell/4683900 to your computer and use it in GitHub Desktop.
Save shanestillwell/4683900 to your computer and use it in GitHub Desktop.
Appcelerator code for click and drag an object. This particular one is constrained to just moving up and down.
var self = Titanium.UI.createWindow({
title:'Window',
left:0,
top:0,
backgroundColor:'#FFF',
name:'win1'
});
var container = Ti.UI.createView({
height: 300,
width: 250,
backgroundColor: 'blue'
});
self.add(container);
var view = Ti.UI.createView({
width : 200,
height : 100,
backgroundColor : 'green'
});
var olt = Titanium.UI.create3DMatrix(), curX, curY, distFromTop;
view.addEventListener('touchstart', function(e) {
curX = e.x;
curY = e.y;
distFromTop = view.rect.y;
});
view.addEventListener('touchmove', function(e) {
var deltaX = e.x - curX,
deltaY = e.y - curY;
olt = olt.translate(0, deltaY, 0);
view.animate({
transform : olt,
duration : 10
});
});
view.addEventListener('touchend', function(e) {
console.log(this.rect.y);
});
container.add(view);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment