UIImageView 的替代品,用于动画,无需一次性将所有图像加载到内存中,并在动画完成后提供回调。
- (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];
}
如果您正在使用 CocoaPods
,这是最简单的。将以下内容添加到您的 Podfile
并运行 pod install
pod 'MCAnimationView', :git => 'https://github.com/mirego/MCAnimationView.git'
不要忘记在需要的地方包含 #import "MCAnimationView.h"
。
MCAnimationView 由 © 2013 Mirego 出品,可根据 新 BSD 许可证免费分发。参阅 LICENSE.md
文件。
Mirego 是一支充满激情的团队,我们相信工作是一个你可以创新和享受乐趣的地方。我们在美丽的魁北克市自豪地构建移动应用程序,包括 iPhone、iPad、Android、Blackberry、Windows Phone 和 Windows 8。
我们还喜爱 开源软件,努力从我们的项目中提取尽可能多的代码以回馈社区。