#import <ImageIO/ImageIO.h>
NSData *gifData = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@“xxx” ofType:@"gif"]];
NSMutableArray *frames = nil;
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)gifData, NULL);
double total = 0;
NSTimeInterval gifAnimationDuration;
if (src) {
size_t l = CGImageSourceGetCount(src);
if (l > 1){
frames = [NSMutableArray arrayWithCapacity: l];
for (size_t i = 0; i < l; i++) {
CGImageRef img = CGImageSourceCreateImageAtIndex(src, i, NULL);
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(src, 0, NULL));
if (dict){
NSDictionary *tmpdict = [dict objectForKey: @"{GIF}"];
total += [[tmpdict objectForKey: @"DelayTime"] doubleValue] * 100;
}
if (img) {
[frames addObject: [UIImage imageWithCGImage: img]];
CGImageRelease(img);
}
}
gifAnimationDuration = total / 100;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.animationImages = frames;
imageView.animationDuration = gifAnimationDuration;
[imageView startAnimating];
imageView.frame=CGRectMake((i-1)*[UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[pageContairView addSubview:imageView];
}
}