美文网首页
iOS - Gif播放

iOS - Gif播放

作者: Mn_Su | 来源:发表于2017-06-14 17:35 被阅读0次

** 1.系统UIImageView 多张图片组成动画(帧动画)**

-(void)MSUGifPlay  {  
    //    NSArray  *array=@[@"image0.png",@"image1.png",@"image2.png"];  
    //    UIImageView  *imgview= [UIImageView imageViewAnimation:CGRectMake(50,80, 550/2, 200)  imageNames:array duration:1];      
    UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50,80, 550/2, 200)];   
    animatedImageView.animationImages =@[[UIImage imageNamed:@"image0"],     

** 2.利用第三方库**

 **1)SDWebImageView里的UIImage+GIF**

        -(void)MSUGifPlay  {    
            UIImage  *image=[UIImage sd_animatedGIFNamed:@"test"];  
            UIImageView  *gifview=[[UIImageView alloc]initWithFrame:CGRectMake(50,80,image.size.width, image.size.height)];    
            gifview.backgroundColor=[UIColor orangeColor];      
            gifview.image=image;   
           [self.view addSubview:gifview];
      } 

**2)IImageView-PlayGIF  YFGIFImageView**

        /**   *  UIImageView-PlayGIF 是 UIImageView 子类,用来显示 GIF。UIIMageView-PlayGIF 性能高,而且占用的内存很低。   *  https://github.com/yfme/UIImageView-PlayGIF   *  Memory-21.9M   *  #import "YFGIFImageView.h"   */  
    -(void)MSUGifPlay  {     
         NSString  *gifPath=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"];
         YFGIFImageView  *gifview=[[YFGIFImageView alloc]init];    
         gifview.backgroundColor=[UIColor clearColor];    
         gifview.gifPath=gifPath;   
         gifview.frame=CGRectMake(50, 100,550/2, 200);    
          [self.view addSubview:gifview];   
          [gifview startGIF];
      }    

 **3)SCGIFImageView**

        /**   *  摘要: SCGIFImageView是一个开源的GIF图片动画显示控件,通过将GIF的每一帧都取出来生成UIImage对象存放在一个数组中,然后使用NSTimer进行动画轮转。   *  https://github.com/shichangone/SCGifExample   *  Memory-22.5M   *  #import "SCGIFImageView.h"   */  
    -(void)MSUGifPlay  {   
       NSString* filePath = [[NSBundle mainBundle] pathForResource:@"test.gif" ofType:nil]; 
       NSData* imageData = [NSData dataWithContentsOfFile:filePath];    
       SCGIFImageView* gifImageView = [[SCGIFImageView alloc]init];      
       [gifImageView setData:imageData];     
        gifImageView.frame = CGRectMake(50,100, gifImageView.image.size.width, gifImageView.image.size.height); 
       [self.view addSubview:gifImageView]; 
     }    

 **4)YLGIFImage**

            /**   *  YLGIFImage 是异步 GIF 图像解码器和图像查看器,支持播放 GIF 图像,而且使用很少的内存。   *  https://github.com/liyong03/YLGIFImage   *  Memory-22.7M   *  #import "YLImageView.h"   *  #import "YLGIFImage.h"   */ 
     -(void)MSUGifPlay  { 
         YLImageView* imageView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 160, 320, 240)];    
        [self.view addSubview:imageView];  
        imageView.image = [YLGIFImage imageNamed:@"test.gif"]; 
     }    

3. 为MBProgressHUD 添加加载动画

        /**   *  MBProgressHUD 添加加载动画   *  Memory-23.8M   *  #import "UIImage+GIF.h"   *  #import "MBProgressHUD.h"   */  
    -(void)MSUGifPlay  {    
          UIImage  *image=[UIImage sd_animatedGIFNamed:@"test"];   
          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.color=[UIColor grayColor];//默认颜色太深了     
         hud.mode = MBProgressHUDModeCustomView;  
         hud.labelText = @"加载中...";      
         hud.customView=gifview; 
     }

相关文章

  • Swift (四) gif图片播放

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

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

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

  • 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图片

    iOS 播放 gif最棒的库,简单高效。Animated GIFs implemented the right w...

  • ios处理图片的一些小Tip(转)

    如何把 GIF 动图保存到相册? iOS 的相册是支持保存 GIF 和 APNG 动图的,只是不能直接播放。用 [...

  • iOS 播放 gif 动画

    使用UIWebView播放 将GIF图片分解成多张PNG图片,使用UIImageView播放

网友评论

      本文标题:iOS - Gif播放

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