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>
你的一次推荐就是对我莫大的支持。感觉不错,给个推荐或者评论吧。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步