Skip to content

Instantly share code, notes, and snippets.

@pec1985
Last active October 13, 2015 06:48
Show Gist options
  • Save pec1985/4155745 to your computer and use it in GitHub Desktop.
Save pec1985/4155745 to your computer and use it in GitHub Desktop.
Zoomable image
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();
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