因为项目需要实现动画效果,便找了相关方面的示例代码,发现资料还是比较少的,能正常测试的也很少。
现在我把自己在网上学到的动画效果重新整理以下,作个简单的备忘。可以运行
打开"xcode"创建一个“window based”的项目就行,我这里命名为animatedImage
animatedImageAppDelegate.h
@interface animatedImageAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UIImageView *animatedImages;//在interface builder中创建一个imageView,让它连接到animateImage App Delegate上的animatedImages
NSMutableArray *imageArray;//用于存放一系列的图片
}
-------------------------------------------------------------------------
animatedImagesAppDelegate.m
@implementation animatedImagesAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// 初始化一定长度的数组
imageArray = [[NSMutableArray alloc] initWithCapacity:23];
// 循环向数组中添加uiimage.图片的名字是从30001.png到30023.png
for (int i = 30001; i <= 30023; i++)
[imageArray addObject:[UIImage imageNamed:
[NSString stringWithFormat:@"%d.png", i]]];
//这里用来初始化图片
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
// 一次循环的时间
animatedImages.animationDuration =5.0;
// 循环次数
animatedImages.animationRepeatCount = 1;
[window makeKeyAndVisible];
//开始动画
animatedImages.startAnimating;
}
编译运行看看把。呵呵,还是挺不错的!