github地址: https://github.com/mancongiOS/UIImage.git
方式一: 用动画展示
UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; gifImageView.backgroundColor = [UIColor orangeColor]; NSArray *gifArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], [UIImage imageNamed:@"3.png"], [UIImage imageNamed:@"4.png"], [UIImage imageNamed:@"5.png"], [UIImage imageNamed:@"6.png"], [UIImage imageNamed:@"7.png"], [UIImage imageNamed:@"8.png"], nil]; gifImageView.animationImages = gifArray; //动画图片数组 gifImageView.animationDuration = 5; //执行一次完整动画所需的时长 gifImageView.animationRepeatCount = MAXFLOAT; //动画重复次数 [gifImageView startAnimating]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // [gifImageView stopAnimating]; }); [self.view addSubview:gifImageView];
方式二:用UIWebView展示
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -44, self.view.bounds.size.width, self.view.bounds.size.height + 44)]; webView.userInteractionEnabled = NO; webView.backgroundColor = [UIColor redColor]; NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; NSString * htmlPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; NSString * htmlCont = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil]; [webView loadHTMLString:htmlCont baseURL:baseURL]; [self.view addSubview:webView];
其中的HTML文件
<!DOCTYPE html> <html> <head> </head> <body> <IMG src="gif.gif" border=0 width="100%" height="100%"> </body> </html>