Giter Club home page Giter Club logo

fxanimationengine's Introduction

FXAnimationEngine

δΈ­ζ–‡ 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

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.

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.

fxanimationengine's People

Contributors

shawnfoo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.