Skip to content

Instantly share code, notes, and snippets.

@dominikkukacka
Created January 11, 2012 09:17
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 dominikkukacka/1593864 to your computer and use it in GitHub Desktop.
Save dominikkukacka/1593864 to your computer and use it in GitHub Desktop.
Titanium Smooth Drag
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();
@dimohamdy
Copy link

not smooth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment