Created
July 4, 2013 05:40
-
-
Save mauropm/5925157 to your computer and use it in GitHub Desktop.
Vertical automatic scrollableview. This will automatically add views in the end and remove views from the beginning of the views array. USE: Create a new mobile project in Ti Studio (classic titanium) and paste this to app.js. With some code from Dawson: https://gist.github.com/dawsontoth/839218 (to do the vertical part)
This file contains hidden or 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 = Ti.UI.createWindow({ | |
backgroundColor:'white', | |
}); | |
// *** This is taken from Dawsontoth's https://gist.github.com/dawsontoth/839218 | |
var rotate = Ti.UI.create2DMatrix().rotate(90); | |
var counterRotate = rotate.rotate(-180); | |
// *** end of the code taken from Dawsontoth's | |
function randomInt(min, max) { | |
return Math.round(min + Math.random()*(max-min)); | |
} | |
function getView(){ | |
var rnd = randomInt(0,200) % 3; | |
var color = 'black'; | |
switch(rnd){ | |
case 0: | |
color='gray'; | |
break; | |
case 1: | |
color='pink'; | |
break; | |
case 2: | |
color='yellow'; | |
break; | |
default: | |
color='black'; | |
break; | |
} | |
return Ti.UI.createView({ | |
backgroundColor:color, | |
top:0, | |
left:0, | |
height: Ti.UI.FILL, | |
weight: Ti.UI.FILL, | |
transform:counterRotate, | |
}); | |
} | |
var autoscroll = Ti.UI.createScrollableView({ | |
showPagingControl:false, | |
height: 320, | |
width: 480, | |
transform:rotate, | |
}); | |
for(i=0;i<10;i++){ | |
autoscroll.addView(getView()); | |
} | |
setInterval(function(){autoscroll.removeView(0); Ti.API.info("Removed head");},3000); | |
setInterval(function(){autoscroll.addView(getView()); Ti.API.info("Added view");},2500); | |
win.add(autoscroll); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment