Latest 1.0.1
Homepage https://github.com/ShawnFoo/FXAnimationEngine
License MIT
Platforms ios 7.0, requires ARC
Frameworks UIKit
Authors

中文
iOS 7.0+
pod
License

An engine to display image frames in animation without causing high-memory usage.

Features

  • Only the displaying image, rather than all of image frames, would occupy the memory.
  • Supports image decode in background thread.
  • Implemented by CADisplayLink.

Previews

FXAnimationEngine

FXAnimationEngine

Using Engine

import "CALayer+FXAnimationEngine.h" in your file first.

// 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 {
    // ...
}

Memory Usage Profile

Do The Math

For example, now you have 100 keyframe images and each one image is 160px 320px. If every frame is 32-bit PNG, then one pixel will occupy 32 / (8 1024) KB. So one image will use 160 320 32 / (8 * 1024) KB memory, that is 200KB.

If you create your keyframe animation by Core Animation, all images will be loaded into memory(200KB * 100 / 1024 MB).

With FXAnimationEngine, creating a keyframe animation won’t cause high-memory waterline, since only one image(200KB) occupies memory during animation.

Demo Allocation Test

FXKeyframeAnimation
FXAnimationEngine

CAKeyframeAnimation
FXAnimationEngine

How To Use Demo

This demo implements a living room using custom animation configuration to create FXKeyframeAnimation or CAKeyframeAnimation.

Installation

Cocoapods(iOS7+)

  1. Add these lines below to your Podfile

    platform :ios, 'xxx'
    target 'xxx' do
      pod 'FXAnimationEngine', '~> 1.0.0'
    end
  2. Install the pod by running pod install

Manually(iOS7+)

Drag FXAnimationEngine document with all files in it to your project

License

FXAnimationEngine is provided under the MIT license. See LICENSE file for details.

Latest podspec

{
    "name": "FXAnimationEngine",
    "version": "1.0.1",
    "summary": "An engine to play image frames in animation without causing high-memory usage.",
    "homepage": "https://github.com/ShawnFoo/FXAnimationEngine",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Shawn Foo": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/ShawnFoo/FXAnimationEngine.git",
        "tag": "v1.0.1"
    },
    "source_files": "FXAnimationEngine/*.{h,m}",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This