All Projects → marmelroy → Interpolate

marmelroy / Interpolate

Licence: mit
Swift interpolation for gesture-driven animations

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
shell
77523 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Interpolate

React Interactive
Better hover, active and focus states than CSS pseudo classes, and a callback when the interactive state changes
Stars: ✭ 115 (-93.64%)
Mutual labels:  interactive
Aicustomviewcontrollertransition
Easy and tidy way for creating custom UIViewController transitions for iOS
Stars: ✭ 130 (-92.81%)
Mutual labels:  interactive
Spade
Spatial Data Structures for Rust
Stars: ✭ 135 (-92.54%)
Mutual labels:  interpolation
Lsh
Run interactive shell commands on AWS Lambda
Stars: ✭ 117 (-93.53%)
Mutual labels:  interactive
React Native Keyboard Accessory View
Keyboard accessory (sticky) view for your React Native app. Supports interactive dismiss on iOS.
Stars: ✭ 128 (-92.92%)
Mutual labels:  interactive
Szl
A lightweight, embeddable scripting language
Stars: ✭ 134 (-92.59%)
Mutual labels:  interactive
Graphviz.it
Graphviz fiddling website
Stars: ✭ 109 (-93.97%)
Mutual labels:  interactive
Zalo.github.io
A home for knowledge that is hard to find elsewhere
Stars: ✭ 143 (-92.1%)
Mutual labels:  interactive
Gonum
开源Go语言数值算法库(An open numerical library purely based on Go programming language)
Stars: ✭ 128 (-92.92%)
Mutual labels:  interpolation
Webpack Bundle Analyzer
Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
Stars: ✭ 11,472 (+534.16%)
Mutual labels:  interactive
Sentaku
Utility to make sentaku (selection, 選択(sentaku)) window with shell command.
Stars: ✭ 117 (-93.53%)
Mutual labels:  interactive
Git Cheats
Git Cheats - Interactive Cheatsheet For Git Commands
Stars: ✭ 124 (-93.15%)
Mutual labels:  interactive
Propose
Android Motion Library
Stars: ✭ 134 (-92.59%)
Mutual labels:  interactive
Apexcharts.js
📊 Interactive JavaScript Charts built on SVG
Stars: ✭ 10,991 (+507.57%)
Mutual labels:  interactive
Lstm Crypto Price Prediction
Predicting price trends in cryptomarkets using an lstm-RNN for the use of a trading bot
Stars: ✭ 136 (-92.48%)
Mutual labels:  interpolation
Nova
NOVA is a tool for annotating and analyzing behaviours in social interactions. It supports Annotators using Machine Learning already during the coding process. Further it features both, discrete labels and continuous scores and a visuzalization of streams recorded with the SSI Framework.
Stars: ✭ 110 (-93.92%)
Mutual labels:  interactive
Tweetscape
A WebVR experience displaying tweets in real-time along a 3D timeline
Stars: ✭ 132 (-92.7%)
Mutual labels:  interactive
Githeat
🔥 Interactive heatmap for your git repos
Stars: ✭ 145 (-91.98%)
Mutual labels:  interactive
Interactive machine learning
IPython widgets, interactive plots, interactive machine learning
Stars: ✭ 140 (-92.26%)
Mutual labels:  interactive
Cyclicgen
Deep Video Frame Interpolation using Cyclic Frame Generation
Stars: ✭ 135 (-92.54%)
Mutual labels:  interpolation

Interpolate - Swift interpolation for gesture-driven animations

Platforms Build Status Version Carthage compatible

Interpolate

Interpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations.

Usage

The 🔑 idea of Interpolate is - all animation is the interpolation of values over time.

To use Interpolate:

Import Interpolate at the top of your Swift file.

import Interpolate

Create an Interpolate object with a from value, a to value and an apply closure that applies the interpolation's result to the target object.

let colorChange = Interpolate(from: UIColor.white,
to: UIColor.red,
apply: { [weak self] (color) in
    self?.view.backgroundColor = color
})

Alternatively, you can specify multiple values for the interpolation in an array. The Swift compiler might have issues to infer the type of the array so it's best to be explicit.

let colors: [UIColor] = [UIColor.white, UIColor.red, UIColor.green]
let colorChange = Interpolate(values: colors,
apply: { [weak self] (color) in
    self?.view.backgroundColor = color
})

Next, you will need to define a way to translate your chosen gesture's progress to a percentage value (i.e. a CGFloat between 0.0 and 1.0).

For a gesture recognizer or delegate that reports every step of its progress (e.g. UIPanGestureRecognizer or a ScrollViewDidScroll) you can just apply the percentage directly to the Interpolate object:

@IBAction func handlePan(recognizer: UIPanGestureRecognizer) {
    let translation = recognizer.translation(in: self.view)
    let translatedCenterY = view.center.y + translation.y
    let progress = translatedCenterY / self.view.bounds.size.height
    colorChange.progress = progress
}

For other types of gesture recognizers that only report a beginning and an end (e.g. a UILongPressGestureRecognizer), you can animate directly to a target progress value with a given duration. For example:

@IBAction func handleLongPress(recognizer: UILongPressGestureRecognizer) {
    switch recognizer.state {
        case .began:
            colorChange.animate(1.0, duration: 0.3)
        case .cancelled, .ended, .failed:
            colorChange.animate(0.0, duration: 0.3)
        default: break
    }
}

To stop an animation:

colorChange.stopAnimation()

When you are done with the interpolation altogether:

colorChange.invalidate()

Voila!

What can I interpolate?

Interpolate currently supports the interpolation of:

  • CGPoint
  • CGRect
  • CGSize
  • Double
  • CGFloat
  • Int
  • NSNumber
  • UIColor
  • CGAffineTransform
  • CATransform3D
  • UIEdgeInsets

More types will be added over time.

Advanced usage

Interpolate is not just for dull linear interpolations.

For smoother animations, consider using any of the following functions: easeIn, easeOut, easeInOut and Spring.

// Spring interpolation
let shadowPosition = Interpolate(from: -shadowView.frame.size.width,
to: (self.view.bounds.size.width - shadowView.frame.size.width)/2,
function: SpringInterpolation(damping: 30.0, velocity: 0.0, mass: 1.0, stiffness: 100.0),
apply: { [weak self] (originX) in
    self?.shadowView.frame.origin.x = originX
})

// Ease out interpolation
let groundPosition = Interpolate(from: CGPoint(x: 0, y: self.view.bounds.size.height),
to: CGPoint(x: 0, y: self.view.bounds.size.height - 150),
function: BasicInterpolation.easeOut,
apply: { [weak self] (origin) in
    self?.groundView.frame.origin = origin
})

In fact, you can easily create and use your own interpolation function - all you need is an object that conforms to the InterpolationFunction protocol.

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'Interpolate', '~> 1.3.0'

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Interpolate into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/Interpolate"

Inspiration

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].