iOS加载gif动画

724 阅读1分钟

貌似方法很多,我找了一个利用SDWebImage库实现加载gif动画的方法,刚开始自己照着代码打的,就是没有效果,后来干脆直接复制了,还是不行-_-!!!. 后来,找解决方法,试了下写gif图片名字的时候将后缀加上,还是不行...

不知道哪来的想法,将gif图片拉到文件夹下,然后command+R, 效果出来了! 步骤:

  • 导入头文件(前提你已经在工程中导入SDWebImage库)#import "UIImage+GIF.h"
- (void)loading
{
    UIImage *loadingImg = [UIImage sd_animatedGIFNamed:@"loading"];
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 50)/2.0, 100, 50, 50)];
    imgView.backgroundColor = [UIColor orangeColor];
    imgView.image = loadingImg;
    [self.view addSubview:imgView];
}

注: gif图片在xcassets中使用此方法不能实现加载效果.

效果:

Simulator Screen Shot 2016年10月13日 00.22.00.png