-
-
Save gbaldera/6114839 to your computer and use it in GitHub Desktop.
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(); | |
var images = []; | |
for(var i = 1; i < 100; i++){ | |
// Assuming all the images are called image1.jpg, image2.jpeg, etc... | |
images.push('/images/image'+i+'.jpg'); | |
} | |
var gallery = Gallery(images,0); | |
win.add(gallery.view); | |
win.open(); |
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
function Gallery(images, startAt) { | |
images = images || []; | |
startAt = startAt || 0; | |
var views = []; | |
var imgs = []; | |
for(var i = 0, len = images.length; i < len; i++) { | |
var zoomable = Zoomable(images[i]); | |
views.push(zoomable.view); | |
imgs.push(zoomable.image); | |
} | |
var scrollable = Ti.UI.createScrollableView({ | |
views: views, | |
currentPage: startAt | |
}); | |
return { | |
view: scrollable | |
} | |
} |
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
function Zoomable(image) { | |
var scroll = Ti.UI.createScrollView({ | |
width: Ti.UI.FILL, | |
height: Ti.UI.FILL, | |
contentWidth: 'auto', | |
contentHeight: 'auto', | |
}); | |
var image = Ti.UI.createImageView({ | |
image: image, | |
width: Ti.UI.SIZE, | |
height: Ti.UI.SIZE | |
}); | |
function onLoad() { | |
image.removeEventListener('load', onLoad); | |
var ratio = 0, | |
width = image.rect.width, | |
height = image.rect.height; | |
if(width > height) { | |
ratio = scroll.rect.width / width; | |
} else { | |
ratio = scroll.rect.height / height | |
} | |
scroll.minZoomScale = ratio; | |
scroll.zoomScale = ratio; | |
image.image = image.image; | |
} | |
image.addEventListener('load', onLoad); | |
scroll.add(image); | |
return { | |
view: scroll, | |
image: image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment