Git Product home page Git Product logo

flipbook's Introduction

Flipbook

A Swift tool for rendering UIViews to image sequences for use with WatchKit, and an accompanying sample WatchKit project.

## Usage

Firstly, drag Flipbook.swift into your project.

There are two ways to use Flipbook.

  1. Create a new Flipbook, and simply attach it to a target view. You must provide a duration (how long to capture snapshots for), and an image prefix (used to name snapshot pngs):

     activityFlipbook = Flipbook()
     activityFlipbook.renderTargetView(activity, duration: 1.0, imagePrefix: "activity")
     activity.startAnimating()
    
  2. Create a new Flipbook, provide a target view, and update its appearance for each frame:

     arcFlipbook = Flipbook()
         
     arcFlipbook.renderTargetView(arcView, imagePrefix: "arc", frameCount: 60) { (view, frame) in
         if let arcView = view as? ArcView {
             arcView.shapeLayer.strokeEnd = CGFloat(frame) * (1.0 / 60.0)
         }
     }
    

The frame parameter provided by the update block will be an integer from 0 to frameCount.

## Where are my images?

Once you've run your app and captured your frames, the debug console will contain the path where your images are saved. It's much easier to record using the iOS simulator, as the path is easily accessible.

[Flipbook] Starting capture...
[Flipbook] Images exported to: /Users/frosty/Library/Developer/CoreSimulator/Devices/2CC4876B-9C2F-4653-A7F4-5EFA5A038BEA/data/Containers/Data/Application/62499F6C-87C7-4C88-9300-5E113862C447/Documents
[Flipbook] Capture complete!

Open up the directory in Finder or the console, and you'll see all the images.

Animating images in WatchKit

The provided project also includes a sample WatchKit App, which animates some demo images. Animating images is quite straightforward:

  1. Drag your image sequence into your WatchKit App.

  2. Add a WKInterfaceImage to your Storyboard and hook it up to an outlet in your interface controller.

  3. Set the image name of the WKInterfaceImage to your imagePrefix plus a dash:

     arcImage.setImageNamed("arc-")
    
  4. Start animating:

     arcImage.startAnimatingWithImagesInRange(NSMakeRange(0, 60), duration: 1.0, repeatCount: 0)
    

flipbook's People

Contributors

frosty avatar stonesam92 avatar tp 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.