UIImageView alternative for animations that doesn't need to load all the images in memory at once and provide a callback when animation is done.
- (void)funWithAnimations
{
/*
Load 48 images in images array for animation.
load0001.png
load0002.png
...
load0048.png
*/
NSUInteger quantity = 48;
NSMutableArray* images = [@[] mutableCopy];
for (NSUInteger index=1; index<=quantity; index++) {
NSString* imageName = [NSString stringWithFormat:@"load%04d.png", index];
UIImage* image = [UIImage imageNamed:imageName];
[images addObject:image];
}
/*
Create the animation view and use it.
*/
MCAnimationView* animationView = [[MCAnimationView alloc] initWithFrame:CGRectZero];
[animationView setAnimation:images];
[animationView setAnimationDuration:2.0f]; // 2 seconds,
/*
Start the animation
*/
[animationView playAnimationRepeatCount:5 willPlayBlock:^(NSUInteger repetition) {
// Animation will play
} didPlayBlock:^(NSUInteger repetition) {
// Animation done playing
}];
/*
When you're done playing it.
*/
[animationView stopAnimations];
}
If you're using CocoaPods
, there's nothing simpler.
Add the following to your Podfile
and run pod install
pod 'MCAnimationView', :git => 'https://github.com/mirego/MCAnimationView.git'
Don't forget to #import "MCAnimationView.h"
where it's needed.
MCAnimationView is © 2013 Mirego and may be freely
distributed under the New BSD license.
See the LICENSE.md
file.
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for iPhone, iPad, Android, Blackberry, Windows Phone and Windows 8 in beautiful Quebec City.
We also love open-source software and we try to extract as much code as possible from our projects to give back to the community.