Created
January 11, 2012 09:17
-
-
Save dominikkukacka/1593864 to your computer and use it in GitHub Desktop.
Titanium Smooth Drag
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 win = Titanium.UI.createWindow({ | |
title:'Window', | |
left:0, | |
top:0, | |
backgroundColor:'#FFF', | |
name:'win1' | |
}); | |
var circleSize = 100; | |
var circleX = 145; | |
var circleY = 0; | |
var circle = Titanium.UI.createView({ | |
height:circleSize, | |
width:circleSize, | |
anchorPoint:{x:(circleSize/2),y:(circleSize/2)}, | |
borderRadius:(circleSize/2), | |
backgroundColor:'#00ff00', | |
top:10 | |
}); | |
var circle2 = Titanium.UI.createView({ | |
height:circleSize, | |
width:circleSize, | |
anchorPoint:{x:(circleSize/2),y:(circleSize/2)}, | |
borderRadius:(circleSize/2), | |
backgroundColor:'#ff0000', | |
top:10 | |
}); | |
var label = Titanium.UI.createLabel({ | |
text:'Click circle repeatedly to animate or drag the circle', | |
bottom:100, | |
color:'#555', | |
font:{fontSize:12,fontFamily:'Helvetica Neue'}, | |
textAlign:'center', | |
height:'auto', | |
width:'auto' | |
}); | |
circle2.addEventListener('touchstart', function(e) { | |
circle.setVisible(true); | |
circle2.setVisible(false); | |
}); | |
circle2.addEventListener('touchmove', function(e) { | |
circle.setTop(e.y + circleY - (circleSize/2)); | |
circle.setLeft(e.x + circleX - (circleSize/2)); | |
}); | |
circle2.addEventListener('touchcancel', function(e) { moveend(e); }); | |
circle2.addEventListener('touchend', function(e) { moveend(e); }); | |
function moveend(e) | |
{ | |
circleY = circle.getTop(); | |
circleX = circle.getLeft(); | |
circle2.setTop(circle.getTop()); | |
circle2.setLeft(circle.getLeft()); | |
circle.setVisible(false); | |
circle2.setVisible(true); | |
} | |
win.add(circle); | |
win.add(circle2); | |
win.add(label); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not smooth