Created
January 31, 2013 15:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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