iOS学习-使用FLAnimatedImage加载Gif

安装第三方库

pod 'FLAnimatedImage'

引入头文件 FLAnimatedImage

#import "FLAnimatedImageView+WebCache.h"

新建一个FLAnimatedImageView

@property (strong, strong) FLAnimatedImageView *music_play_view;

 创建gif视图,可以使用本地文件或者url展示

    _music_play_view = [FLAnimatedImageView new];
    [self addSubview:_music_play_view];
    [_music_play_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.left.mas_equalTo(19);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    //文件在本地
    NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"PlayMusic.gif" ofType:nil]];
    //文件时URL
    //NSData *localData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://xxx.xxx.xxx/media/active_page/1ffN9fa1_20190720092942_301.gif"]];
    FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:localData];
    _music_play_view.animatedImage = animatedImage;

你可能感兴趣的:(ios,学习,cocoa,cocoapods,objective-c,xcode)