Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@dimohamdy

dimohamdy Feb 3, 2015

not smooth

dimohamdy commented Feb 3, 2015

not smooth

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