zoukankan      html  css  js  c++  java
  • 加载Gif图片方法

    1、使用webView(直接加载已有gif图片)

    NSString *filePath1 = [[NSBundle mainBundle]pathForResource:@"girl.gif" ofType:nil];
    
        NSData *webGifData = [NSData dataWithContentsOfFile:filePath1];
        
        UIWebView *webView = [[UIWebView alloc]init];
        
        webView.frame = CGRectMake(100, 20, 100, 100);
        
        webView.backgroundColor = [UIColor blueColor];
        
        webView.scalesPageToFit = YES;
    //最好设置一下userInteractionEnabled这个属性
        webView.userInteractionEnabled = NO;
        
       [webView loadData:webGifData MIMEType:@"image/gif" textEncodingName:@"" baseURL:[NSURL URLWithString:@""]];
        
        [self.view addSubview:webView];
    

     2、使用分组图(需要UI切图,图片起名字最好规范一些!!!,其实就是逐帧动画,O(∩_∩)O哈哈哈~)

    UIImageView *imagesView = [[UIImageView alloc]init];
        
        imagesView.frame = CGRectMake(100, 140, 100, 100);
        
        NSMutableArray *array  = [NSMutableArray new];
        
        for (int i = 0; i<14; i++) {
            
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading_0000%d",i]];
            
            [array addObject:image];
        }
        
         imagesView.animationImages = array;
        
         imagesView.animationDuration = 0.5;
        
         imagesView.animationRepeatCount =  MAXFLOAT;//这里也可以设置重复次数.
        
         [imagesView startAnimating];
        
         [self.view addSubview: imagesView];
    

     3、使用了SDwebImage第三方,导入"UIImage+GIF.h"头文件

    NSString  *Path = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"dog.gif" ofType:nil];
        
        NSData  *imageData = [NSData dataWithContentsOfFile:Path];
        
        UIImageView *sdImage = [UIImageView new];
        
        sdImage.image = [UIImage sd_animatedGIFWithData:imageData];
    
    
        sdImage.frame = CGRectMake(100, 260, 150, 100);
        
        [self.view addSubview:sdImage];
    

     4、从网络下载图片(这里使用的是SDwebimge方法)

     NSString *urlString = @"http://c.hiphotos.baidu.com/zhidao/pic/item/3801213fb80e7becf636ec082c2eb9389a506b6f.jpg";
       
        NSURL    *url       = [NSURL URLWithString:urlString];
        
        NSData   *data      = [NSData dataWithContentsOfURL:url];
    
        UIImageView *imageView  = [[UIImageView alloc]init];
        
        imageView.frame = CGRectMake(100, 380, 150, 100);
        
        imageView.image = [UIImage sd_animatedGIFWithData:data];
        
        imageView.backgroundColor = [UIColor redColor];
        
        [self.view addSubview:imageView];
    
  • 相关阅读:
    电影投票使用到index索引 isdigit range += format upper
    for循环删除列表里的内容 删除字典中的内容
    3.格式化输出 format 三种方法集合% f
    列表和字符串的转换及statswith,endswith的应用判断
    过滤器,使用到in for break
    sort排序及reverse反转的结合使用
    列表内的改动
    django 第五天 自定义标签 静态文件
    Mysql 基础 1
    django 第四天模板渲染
  • 原文地址:https://www.cnblogs.com/superbobo/p/5385850.html
Copyright © 2011-2022 走看看