Skip to content

Instantly share code, notes, and snippets.

@jabubuck
Created May 10, 2013 18:44
Show Gist options
  • Save jabubuck/5556496 to your computer and use it in GitHub Desktop.
Save jabubuck/5556496 to your computer and use it in GitHub Desktop.
Small sample that demonstrates a drag down view, for Titanium, works with iOS and Android.
var screenHeight = Ti.Platform.displayCaps.platformHeight;
var screenWidth = Ti.Platform.displayCaps.platformWidth;
var win = Ti.UI.createWindow({
fullscreen: true,
height: screenHeight,
width: screenWidth,
backgroundColor: 'white'
});
var movePos = 0;
var currentY;
var yPos = 0 - (screenHeight / 2);
//This is the view that will be dragged down
var view =Ti.UI.createView({
backgroundColor: 'red',
height: screenHeight / 2,
width: screenWidth,
top: yPos
});
//Calculate whether the view should scroll up
view.addEventListener('touchstart', function (e){
currentY = e.y;
});
view.addEventListener('touchmove', function(e){
if(e.y < (currentY)){
view.animate({top: yPos, duration: 1000});
}
});
//Calculate whether the view should scroll down
win.add(view);
win.addEventListener('touchstart', function (e){
currentY = e.y;
});
win.addEventListener('touchmove', function(e){
if(e.y > (currentY + 10)){
view.animate({top: 0, duration: 1000});
}
});
win.add(view);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment