Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created February 7, 2012 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/1760898 to your computer and use it in GitHub Desktop.
Save kwhinnery/1760898 to your computer and use it in GitHub Desktop.
var CustomImageView = require('CustomImageView');
var w = Ti.UI.createWindow({
backgroundColor:'white'
});
var i = new CustomImageView({
animatedImages:[
'/images/1.png',
'/images/2.png'
],
height:40,
width:40,
duration:1000,
repeatCount:2
});
w.add(i);
setTimeout(function() {
i.startAnimation();
},1000);
w.open();
function CustomImageView(args) {
var self = Ti.UI.createImageView(args);
//override any customizations to image, images, repeatCount, or duration
self.image = args.animatedImages[0];
self.repeatCount = null;
self.duration = null;
//instance variables
var animationIndex = 0,
animationCount = 0,
images = args.animatedImages;
self.startAnimation = function() {
if (animationCount < args.repeatCount*images.length) {
animationIndex++;
if (animationIndex === images.length) {
animationIndex = 0;
}
self.image = images[animationIndex];
animationCount++;
setTimeout(self.startAnimation, args.duration);
}
};
return self;
}
module.exports = CustomImageView;
@HazemKhaled
Copy link

thanks, working with me :)

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