• Stars
    star
    511
  • Rank 86,473 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A toolkit for creating interactive menus and tutorials in Swift

TweenController travisci codecov Swift v4.1 License MIT CocoaPods Carthage

On the surface, TweenController makes it easy to build interactive menus and tutorials. Under the hood, it's a simple but powerful toolkit to interpolate between values that are Tweenable.

Example

Pinyada

Usage

Tween anything that is Tweenable, such as CGAffineTransform:

func tweenTransform() {
    let transformA = CGAffineTransform.identity
    let transformB = CGAffineTransform(scaleX: 2.0, y: 2.0)
    let transformC = CGAffineTransform(rotationAngle: CGFloat(M_PI_2))
        
    controller.tween(from: transformA, at: 0.0)
        .to(transformB, at: 0.5)
        .then(to: transformC, at: 1.0)
        .with(action: tweenView.layer.twc_applyAffineTransform)
}

or UIColor:

func tweenColor() {
    let colorA = UIColor.green
    let colorB = UIColor.blue
    let colorC = UIColor.red
    tweenView.backgroundColor = colorA
    
    controller.tween(from: colorA, at: 0.0)
        .to(colorB, at: 0.5)
        .then(to: colorC, at: 1.0)
        .with(action: tweenView.twc_applyBackgroundColor)
}

or your own custom type:

enum Step: Int {
    case One = 1, Two = 2, Three = 3, Four = 4
}

extension Step: Tweenable {
    static func valueBetween(_ val1: Step, _ val2: Step, percent: Double) -> Step {
        let val = Int(round(Double(val2.rawValue - val1.rawValue) * percent + Double(val1.rawValue)))
        return Step(rawValue: max(min(val, 4), 1)) ?? .One
    }
}

func tweenStep() {
    tweenController.tween(from: Step.One, at: 0.0)
        .to(.Four, at: 0.25)
        .thenHold(until: 0.75)
        .then(to: .Two, at: 1.0)
        .with { step in
            // use step
    }
}

then simply call:

// can be called in response to user interaction
// such as a gesture recognizer or scroll view
// or something else, like a CADisplayLink

// progress range is arbitrary
// you might choose to use a percentage, like 0.0 - 1.0
// or the content size of a scroll view

controller.update(progress: newProgress)

You can use easing functions:

controller.tween(from: transformA, at: 0.0)
	.to(transformB, at: 1.0, withEasing: Easing.easeInOutQuart)
	.with(action: tweenView.layer.twc_applyAffineTransform)

You can use Key-Value Coding:

controller.tween(from: 0.0, at: 0.0)
    .to(M_PI * 8.0, at: 1.0)
    .with(object: tweenView.layer, keyPath: "transform.rotation.z")

You can also observe boundaries:

func observeBoundaries() {
    controller.observeForward(progress: 0.5) { progress in
        // halfway finished!
    }
    controller.observeBoth(progress: 0.75) { progress in
        // this is called when moving backwards or forwards
    }
}

Standard Tweenables

  • Double
  • Float
  • Int
  • CGFloat
  • CGPoint
  • CGSize
  • CGRect
  • UIColor
  • CGAffineTransform
  • CATransform3D

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate TweenController into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '10.0'
use_frameworks!

pod 'TweenController', '~> 1.0'

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

Carthage

Carthage is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use Homebrew.

$ brew update
$ brew install carthage

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

github "daltonclaybrook/tween-controller" ~> 1.0.1

Then, run the following command to build the TweenController framework:

$ carthage update

At last, you need to set up your Xcode project manually to add the TweenController framework.

On your application targets’ β€œGeneral” settings tab, in the β€œLinked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

On your application targets’ β€œBuild Phases” settings tab, click the β€œ+” icon and choose β€œNew Run Script Phase”. Create a Run Script with the following content:

/usr/local/bin/carthage copy-frameworks

and add the paths to the frameworks you want to use under β€œInput Files”:

$(SRCROOT)/Carthage/Build/iOS/TweenController.framework

For more information about how to use Carthage, please see its project page.

Contact

Follow and contact me on Twitter. If you find an issue, just open a ticket on it. Pull requests are warmly welcome as well.

License

TweenController is released under the MIT license. See LICENSE for details.

More Repositories

1

ProtocolWitness

A Swift macro for generating protocol witnesses for classes/actors
Swift
38
star
2

APISpec

Describe your Swift Vapor API using native code, and generate OpenAPI 3.0 JSON
Swift
25
star
3

ParallaxCollectionCoordinator

A Tool for iOS which Applies a Parallax Effect to Multiple Collection Views
Objective-C
18
star
4

SlidingSegmentedControl

A Unique UIControl Subclass For Displaying Multiple Options
Objective-C
18
star
5

Clangler

A Swift package for parsing Clang module map files
Swift
10
star
6

SpaceFactoryNetworking

A networking library on top of NSURLSession
Objective-C
10
star
7

pebble-game-of-life

Conway's Game of Life simulation in the form of a Pebble watch face.
C
8
star
8

GameBoy

A Game Boy emulator written in Swift
Swift
8
star
9

Settler

A utility for building complex, type-safe dependency graphs in Swift
Swift
8
star
10

SlantyDashedView

A view requested by a redditor
Objective-C
7
star
11

wordle-solver

A little command line app for finding the answer to Wordle
Swift
7
star
12

GitHubDemo

A demo app for iOS using the GitHub API v3 and RxSwift
Swift
6
star
13

NumberParser

A utility used to parse number strings
Swift
5
star
14

AsciiEdit

A utility to edit asciinema files
Swift
4
star
15

snek

Snake for Gameboy
Assembly
4
star
16

SpaceKit

A demonstration of a Swift package that bundles and calls a Rust library
Swift
4
star
17

hls

A proxy server for HLS video streaming
Swift
3
star
18

barnsley-fern

An implementation of the Barnsley Fern in Swift
Swift
3
star
19

telescope

Slackbot that helps teams scope tickets in secret
TypeScript
3
star
20

AppSafe

A command-line utility to audit builds
Swift
3
star
21

AstroSwift

Swift
3
star
22

pizza-button

Node.js function for AWS Lambda and AWS IoT Button that orders Domino's pizza.
JavaScript
3
star
23

captain

Declarative Git Hooks
Swift
2
star
24

advent-of-code

Solutions for Advent of Code 2019
Swift
2
star
25

RxSwiftMVVM

And example of RxSwift and MVVM
Swift
2
star
26

dalton-website

TypeScript
2
star
27

CropKit

Tools and UI for cropping images
Swift
2
star
28

MCPixelArt-Win

A utility for creating Minecraft pixel art from images
C#
2
star
29

gb-gift

Assembly
2
star
30

server-playground

My web app experimentation with Go
Go
2
star
31

go-transfer

Transfer files over HTTP
Go
2
star
32

ScrubWheel

Swift
1
star
33

swerve

A web server focused on controllers and CRUD, written in Go
Go
1
star
34

EtheRemote

A Swift wrapper SDK for Ethereum JSON RPC
Swift
1
star
35

gb-swift

Swift
1
star
36

overwatch-slack

An Overwatch service for Slack
Swift
1
star
37

CLox

An implementation of the CLox compiler from the book Crafting Interpreters
C
1
star
38

Mosaic

A programming language for Game Boy
Swift
1
star
39

GuessingGameSwift

The Swift client for the guessing game on Ethereum
Swift
1
star
40

LiquidityLock

A contract used to lock liquidity for Uniswap V3 pools
Solidity
1
star
41

youbora-lib-fork

Objective-C
1
star
42

daltonclaybrook.github.io

My personal website
TypeScript
1
star
43

aoc

Advent of Code 2021
Rust
1
star
44

GuessingGame

A toy implementation of a guessing game on Ethereum
Solidity
1
star
45

when-is-the-merge

When will The Merge happen?
TypeScript
1
star
46

MCPixelArt-Mac

A utility for creating Minecraft wool pixel art from your own images.
Swift
1
star
47

EtherSwift

Swift
1
star
48

NonogramSolver

Swift
1
star
49

AspectCollectionViewLayout

A collection view layout which preserves the aspect ratios of cells
Swift
1
star
50

dalton-blog

My Personal blog
Ruby
1
star
51

gb-playground

A place to play with Gameboy assembly
Assembly
1
star
52

cricket-temp

Swift
1
star
53

provision

A utility for managing provisioning profiles
Swift
1
star
54

jira-slack

Jira webhooks for Slack
TypeScript
1
star
55

CheckSplitter

Swift
1
star
56

LeftRightCenter

Swift
1
star
57

Gamma

The snapshot testing framework for iOS, written in Swift
Swift
1
star
58

JLox

An implementation of the JLox interpreter from Crafting Interpreters
Java
1
star