FXAnimationEngine 1.0.1

FXAnimationEngine 1.0.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布时间上次发布2018年10月

ShawnFoo 维护。



  • Shawn Foo

FXAnimationEngine

中文 iOS 7.0+ pod License

一个在不引起高内存消耗的情况下显示图像帧的引擎。

特点

  • 仅显示图像,而不是所有图像帧,会占用内存。
  • 支持在后台线程中解码图像。
  • 通过 CADisplayLink 实现。

预览

使用引擎

首先在您的文件中导入 "CALayer+FXAnimationEngine.h"。

// load all image frames 
NSArray<UIImage *> *frames = ...;

FXKeyframeAnimation

FXKeyframeAnimation *animation = [FXKeyframeAnimation animationWithIdentifier:@"xxx"];
animation.delegate = self;
animation.frameImages = frames;
animation.duration = 5.5;
animation.repeats = 3;

// decode image asynchronously
[xxxView.layer fx_playAnimationAsyncDecodeImage:animation];

FXAnimationGroup

FXKeyframeAnimation *animation = [FXKeyframeAnimation animation];
animation.count = 50;  // [0, 49]
animation.duration = 4.2;

FXKeyframeAnimation *animation2 = [FXKeyframeAnimation animation];
animation2.count = 30; // [50, 79]
animation2.duration = 1.5;
animation2.repeats = 6; // repeat image between index 50 to index 79 six times

FXKeyframeAnimation *animation3 = [FXKeyframeAnimation animation];
animation.count = 20; // [80, 99]
animation.duration = 2;

FXAnimationGroup *animationGroup = [FXAnimationGroup animationWithIdentifier:@"xxxAnimation"];
animationGroup.animations = @[animation, animation2, animation3];
animationGroup.frames = frames;
animationGroup.delegate = self;

[xxxView.layer fx_playAnimation:animation];

FXAnimationDelegate

- (void)fxAnimationDidStart:(FXAnimation *)anim {
    // identify your animation by its "identifier" property
}

- (void)fxAnimationDidStop:(FXAnimation *)anim finished:(BOOL)finished {
    // ...
}

内存使用配置文件

计算一下

例如,现在您有100个关键帧图像,每个图像尺寸为160px * 320px。如果每帧是32位PNG,那么一个像素将占用32 / (8 * 1024) KB。因此,一个图像将使用160 * 320 * 32 / (8 * 1024) KB内存,即200KB。

如果您使用Core Animation创建关键帧动画,所有图像都将加载到内存中(200KB * 100 / 1024 MB)。

在FXAnimationEngine中,创建关键帧动画不会导致内存水位线过高,因为在动画过程中只有一张图像(200KB)占用内存。

演示分配测试

FXKeyframeAnimation

CAKeyframeAnimation

如何使用示例

此示例使用自定义动画配置实现了客厅,以创建FXKeyframeAnimation或CAKeyframeAnimation。

安装

Cocoapods(iOS7+)

  1. 在您的Podfile中添加以下行

    platform :ios, 'xxx'
    target 'xxx' do
      pod 'FXAnimationEngine', '~> 1.0.0'
    end
    
  2. 运行 pod install 安装pod

手动安装(iOS7+)

FXAnimationEngine 文档及其所有文件拖放到您的项目中

许可证

FXAnimationEngine遵循MIT许可证提供。有关详细信息,请参阅LICENSE文件。