JMAnimatedImageView 0.2.4

JMAnimatedImageView 0.2.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年5月

Jérôme Morissard 维护。



  • Morissard Jérome

JMAnimatedImageView 是 UIImageView 的一个高性能子类

  • 使用最小的内存压力播放大型图像动画
  • 允许与 imageView 进行手动交互以驱动手动动画
  • 可以用作轮播图
  • 支持 GIF 以加载您的动画

变更日志

0.2.4 :

  • 改进文档
  • 修复 retain cycle(感谢 Instruments!)
  • JMGif 分配以更好地与您喜爱的网络库集成

安装

只需将您的 UIImageView 实例替换为 JMAnimatedImageView 实例。

如果您使用 CocoaPods,最快捷的尝试方法是键入以下内容到命令行

$ pod try JMAnimatedImageView

用法

对于使用 bundle 中的文件进行本地动画

在您的代码中,导入 "JMAnimatedImageView.h""JMAnimatedImageView.h"

//GIF example
@property (weak, nonatomic) IBOutlet JMAnimatedImageView *jmImageView;

[self.jmImageView reloadAnimationImagesFromGifNamed:@"rock"];
self.jmImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition;
[self.jmImageView startAnimating];
//PNG example with manual animation
@property (weak, nonatomic) IBOutlet JMAnimatedImageView *jmImageView;

self.jmImageView.animationDelegate = self;
self.jmImageView.animationDatasource = self;
[self.jmImageView reloadAnimationImages]; //<JMOImageViewAnimationDatasource>
self.jmImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition;
self.jmImageView.memoryManagementOption = JMAnimatedImageViewMemoryLoadImageLowMemoryUsage;
[self.jmImageView startAnimating];

对于远程 GIF

@property (weak, nonatomic) IBOutlet JMAnimatedImageView *jmImageView;

[[JMApi sharedApi] downloadYourGifFileHasData:^(NSData *gifData) {
    self.animatedImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition;
    self.animatedImageView.memoryManagementOption = JMAnimatedImageViewMemoryLoadImageLowMemoryUsage;
    [self.animatedImageView reloadAnimationImagesFromGifData:gifData fromUrl:url];
     [self.animatedImageView startAnimating];
}]; 

对于使用 AFNetworking 的远程 GIF

    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *postOperation = [[AFHTTPRequestOperation alloc] initWithRequest:req];
    [postOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.animatedImageView.animationType = JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition;
        self.animatedImageView.memoryManagementOption = JMAnimatedImageViewMemoryLoadImageLowMemoryUsage;
        [self.animatedImageView reloadAnimationImagesFromGifData:responseObject fromUrl:url];
        [self.animatedImageView startAnimating];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Image error: %@", error);
        block(NO, nil);
    }];

    [postOperation start];

自定义

  • AnimationType
typedef NS_ENUM(NSUInteger, JMAnimatedImageViewAnimationType) {
    JMAnimatedImageViewAnimationTypeInteractive = 0,

    //Animation, carousel effect
    JMAnimatedImageViewAnimationTypeManualSwipe,

    //Automatic rotation, use animationDuration + animationRepeatCount
    JMAnimatedImageViewAnimationTypeAutomaticLinear,    
    JMAnimatedImageViewAnimationTypeAutomaticLinearWithoutTransition,
    JMAnimatedImageViewAnimationTypeAutomaticReverse,
};
  • MemoryOption
typedef NS_ENUM(NSUInteger, JMAnimatedImageViewMemoryOption) {
    JMAnimatedImageViewMemoryLoadImageSystemCache = 0,  //images memory will be retain by system
    JMAnimatedImageViewMemoryLoadImageLowMemoryUsage,   //images loaded but not retained by the system
    JMAnimatedImageViewMemoryLoadImageCustom            //images loaded by you (JMOImageViewAnimationDatasource)
};
  • ImageViewOrder
typedef NS_ENUM(NSUInteger, JMAnimatedImageViewOrder) {
    JMAnimatedImageViewOrderNormal = 1,
    JMAnimatedImageViewOrderReverse = -1
};

多 GIF 和动画类型(顶部交互,左侧自动滑动效果,右侧自动无动画)

Image

JMimageView 可以生成轮播图

Image

JMimageView 允许交互式动画

Image

待办事项

  • 添加对 APNG 的支持
  • 添加对 WebP 动画的支持(正在进行中,但此功能目前尚未支持:[https://chromium.googlesource.com/webm/libwebp/](https://chromium.googlesource.com/webm/libwebp/))
  • * 是否支持视频格式?