美文网首页
iOS 播放本地 gif

iOS 播放本地 gif

作者: Heikki_ | 来源:发表于2017-02-13 14:44 被阅读351次

一.使用 UIWebView 播放

    NSData *gifData = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"IMG_2073" ofType:@"GIF"]];
    //UIWebView生成
    UIWebView *imageWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 302, 400, 400)];
    //用户不可交互
    imageWebView.userInteractionEnabled = NO;
    //加载gif数据
    [imageWebView loadData:gifData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
    //视图添加此gif控件
    [self.view addSubview:imageWebView];

二.使用 UIImageView + SDWebImage

//头文件
#import "UIImage+GIF.h"

-(void)gifPlay{
 UIImage      *image=[UIImage sd_animatedGIFNamed:@"IMG_2073"];
/*
注意 :SDWebImage 默认 动图格式为小写"gif"所以拖到项目中的 gif 文件记得拓展名要小写 否则动图不播放
*/

/*   通过二进制播放
NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_2073" ofType:@"gif"];
NSData *data = [NSData dataWithContentsOfFile:path];
UIImage  *image=[UIImage sd_animatedGIFWithData:data];
*/

 UIImageView  *gifview=[[UIImageView alloc]initWithFrame:CGRectMake(50,50,image.size.width, image.size.height)];
 gifview.image=image;
 [self.view addSubview:gifview];
 }

三. 自定义 MBProgressHUD
UIImageView + SDWebImage + MBProgressHUD

#import "UIImage+GIF.h"
#import "MBProgressHUD.h" 
-(void)showHUD {
    UIImage *image=[UIImage sd_animatedGIFNamed:@"IMG_2073"];
    UIImageView  *gifview=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,image.size.width/2, image.size.height/2)];
    gifview.image=image;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //背景颜色
    hud.backgroundColor = [UIColor redColor];
    //文字颜色
    hud.contentColor = [UIColor blueColor];
    //内容背景颜色
    hud.bezelView.backgroundColor =  [UIColor orangeColor];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = @"加载中....";
    hud.customView=gifview;
}

相关文章

  • iOS 播放本地 gif

    一.使用 UIWebView 播放 二.使用 UIImageView + SDWebImage 三. 自定义 MB...

  • iOS - Gif图片本地播放

    在本地Gif播放中 我们需要使用到import ImageIO,大多数图片的处理中都可能需要用到import Im...

  • Swift (四) gif图片播放

    @[TOC](IOS gif图片播放 swift) 1. GIF在iOS平台上的几种加载方式 使用Dispatch...

  • iOS-播放gif动画文件(OC方法)

    iOS-.gif动画文件的播放 前言 播放gif动画的方法有多种: 将gif图片分解成多张图片使用UIImageV...

  • iOS-GIF图播放

    封装播放GIF图片的Imageview分类GIF图片来源为本地或网络导入系统库: import ImageIO 加...

  • iOS 播放GIF

    iOS默认是不支持播放GIF图片的,但是系统也没有禁止播放它,该有的API还是有的,下面就 来一发吧! 一定要导入...

  • iOS - Gif播放

    ** 1.系统UIImageView 多张图片组成动画(帧动画)** ** 2.利用第三方库** 3. 为MBPr...

  • iOS的gif的图片处理

    iOS上没有直接播放gif控件(gif图片是几张png格式经过播放之后显示的不同的帧来进行实现的)sdwebima...

  • 关于iOS中Gif播放

    最近看了一下Gif播放,因为iOS是没有可以直接播放Gif资源的控件的,所以,这就需要我们想办法了。。。 准备 通...

  • iOS 播放GIF图

    本文记录两种在iOS上播放GIF的方法 第一种:用UIWebView播放GIF图 如果想让webView的内容自适...

网友评论

      本文标题:iOS 播放本地 gif

      本文链接:https://www.haomeiwen.com/subject/mbzzittx.html