Ubergang is a tweening engine for iOS written in Swift.

Related tags

Animation Ubergang
Overview

Ubergang - a tweening engine for iOS

Platform iOS CocoaPods Compatible License Apache2 iOS

Ubergang is a tweening engine for iOS written in Swift.

Features

  • Tween numeric values, UIColors and CGAffineTransforms
  • Tween along UIBezierPaths
  • Tween through points
  • Linear, Expo, Cubic, Quad, Circ, Quart, Quint, Sine, Back, Bounce and Elastic easings
  • Generic tween setup
  • Repeat and Yoyo tween options
  • Memory management for strong and weak tween object references
  • Tween Timelines
  • Bezier tween align to path
  • Logging and log levels

Previews

Example - Timeline Example - Timeline

Installation

CocoaPods

    platform :ios, '8.0'
    use_frameworks!
    pod 'Ubergang'

Setup

    UTweenSetup.instance.enableLogging(true)
    UTweenSetup.instance.enableLogging(true, withLogger: loggerProxy)

Ubergang provides some logs for basic operations like start, stop, pause, ... There is a dependency to XCGLogger which is used by default, but you can pass any Logger you prefer by creating a custom logger proxy implementing UTweenLoggable.

Tween Configuration

    .options(.repeat(n))
    .options(.yoyo)
    .options(.repeat(n), .yoyo)

Using options you can let the Tween repeat n (Int) times, let it yoyo or combine both options.

  • Repeat will restart the Tween n times where repeatCycleChange will be called with every cycle.
  • Yoyo will reverse the Tween after it reaches the end value.
    .reference(.strong)` //(default)
    .reference(.weak)

reference determines how to handle the reference count for the tween. Ubergang will increase the retain count if the option is set to .strong or won't increase it if it's set to .weak. These two rules are valid for most cases:

  • The Tween is not stored in a field variable -> .strong
  • The Tween is stored in a field variable -> .weak

Usage

Start a simple numeric Tween (Double)

    0.tween(to:10).update({ (value:Int) in print("\(value)") }).start()

This Tween goes from 0 to 10 over 0.5 by default seconds using a linear easing by default. The current value will be printed with every update.

'to' and 'from' using closures

    NumericTween(id: "doubleTween")
            .from({ [unowned self] in return self.position2.x }, to: { [unowned self] in return self.position1.x })
            .update({ value, progress in print("update: \(value), progress: \(progress) ") })
            .duration(5)
            .start()

Passing closures to 'to' and 'from' will always compute all results using the current values returned by the closures.

Start a weak numeric Tween (Int)

    var tween: NumericTween<Int>?

    func run() {
        tween = 0.tween(to: 10)
            .id("intTween")
            .duration(5)
            .update({ value in print("update: \(value)") })
            .ease(.elastic(.out))
            .reference(.weak)
            .start()
    }

This Tween with id 'intTween' goes from 0 to 10 over 5 seconds using an elastic easing. The current value will be printed with every update. .reference(.weak) will store this tween weakly, Ubergang won't increment the reference count. It's up to you to keep the Tween alive.

Start a numeric Tween repeating 5 times with yoyo

    var tween: NumericTween<Int>?

    func run() {
    
        tween = 0.tween(to: 10)
            .id("intTween")
            .duration(5)
            .update({ value in print("update: \(value)") })
            .ease(.elastic(.out))
            .reference(.weak)
            .options(.repeat(5), .yoyo)
            .start()
    }

Start a weak numeric Tween (CGAffineTransform)

    @IBOutlet var testView: UIView!
    var tween: TransformTween?

    func run() {
        //declare the target values
        var to = testView.transform
        to.ty = 200.0
    
        tween = testView.transform.tween(to: transform)
            .id("testView")
            .duration(2.5)
            .reference(.weak)
            .update({ [unowned self] value in self.testView.transform = value })
    	    .start()
    }

This Tween with id 'testView' tweens a transform over 2.5 seconds. The resulting tranform will be assigned to the testView with every update 'welf.testView.transform = value'.

Start a Timeline containing three Tweens

    var timeline: UTimeline = UTimeline(id: "timeline")

    func run() {
        timeline.options(.yoyo).reference(.weak)
        
        timeline.append(
            0.tween(to: 10).id("intTween").duration(5).update({ value, _ in print("0-10 value: \(value)") })
        )
        
        timeline.append(
            0.0.tween(to: 10.0).id("floatTween1").duration(5).update({ value, _ in print("0.0-10.0 value: \(value)") })
        )
        
        timeline.insert(
            10.0.tween(to: 0.0).id("floatTween2").duration(5).update({ value, _ in print("10.0-0.0 value: \(value)") }), at: 2.5
        )
  
        timeline.start()
    }

This Timeline controls one Tween starting at time 0.0 seconds, one Tween starting at time 5.0 seconds and the last one starting at 2.5 seconds. All Tweens are controlled by the timeline with the given options - In this case the tween option .yoyo

Tween along a UIBezierPath

    var tween: BezierPathTween!

    func run() {
    tween = BezierPathTween().along(path)
            .id("bezierTween")
            .duration(5)
            .ease(.linear)
            .reference(.weak)
            .update({ [unowned self] (value: CGPoint, progress: Double) in
                //update
            })
            .start()
    }

Tween through points

    var tween: BezierPathTween!

    func run() {
        let points = [CGPoint]()
        points.append(...)

        tween = BezierPathTween().along(points)
            .id("bezierTween")
            .duration(5)
            .ease(.linear)
            .reference(.weak)
            .update({ [unowned self] (value: CGPoint, progress: Double) in
                //update
            })
            .start()
    }    

Tween through points and use orientation to align the object on update

    var tween: BezierPathTween!

    func run() {
        let points = [CGPoint]()
        points.append(...)

        tween = BezierPathTween().along(points)
            .id("bezierTween")
            .duration(5)
            .ease(.linear)
            .reference(.weak)
            .update({ [unowned self] (value:CGPoint, progress: Double, orientation: CGPoint) in
                self.targetView.center = value

                let angle = atan2(orientation.y, orientation.x)
                let transform = CGAffineTransformRotate(CGAffineTransformIdentity, angle)
                self.targetView.transform = transform
            })
            .start()
    }      

Changelog Verion 1.2.0

  • The Ease type changed to an Enum instead of passing the function type directly e.g.
	.ease(Linear.ease) becomes .ease(.linear)
	.ease(Elastic.easeOut) becomes .ease(.elastic(.out))
  • When starting a tween which is already playing, it will now only log a warning via the logger proxy instead of guarding a restart
  • The new tween direction 'backward' will inverse easings and tween start times within a timeline
/*
    forward -->
t0: |-----------------------|
t1:     |----------------------|
t2: |--------|
*/

/*
                     <-- reverse
t0: |-----------------------|
t1:     |----------------------|
t2: |--------|
*/

/*
                    <-- backward
t0:    |-----------------------|
t1: |----------------------|
t2:                   |--------|
*/

Changelog Verion 1.1.0

  • Swift 5 migration

Changelog Verion 1.0

  • Swift 4 migration
  • Change tween creation pattern (UTweenBuilder removed - Instead instantiate the tween object directly or use the appropriate extension like 0.tween(to: 10))
  • Add @discardableResult to specific methods
  • Fix issue where timelines didn't work if there was a delay between tweens

Feedback is always appreciated

You might also like...
Project 04 I created for
Project 04 I created for "iOS & Swift - The Complete iOS App Development Bootcamp"

Magic 8 Ball This is the fourth project I created for "iOS & Swift - The Complete iOS App Development Bootcamp" Our Goal The objective of this challen

An app that will help UI/UX designers and iOS developpers to easily work together, using demos and examples about iOS capabilities, limitations, ecosystem, ...

Demoapp Work in progress... 👀 What's about? It's an app built in SwiftUI that will help UI/UX designers and iOS developpers to work together smoothly

(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey 🍯 to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey 🍯 to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

A DSL to make animation easy on iOS with Swift.
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

A library to simplify iOS animations in Swift.

Updated for Swift 4.2 Requires Xcode 10 and Swift 4.2. Installation Drop in the Spring folder to your Xcode project (make sure to enable "Copy items i

Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

Swift animation library for iOS, tvOS and macOS.
Swift animation library for iOS, tvOS and macOS.

anim is an animation library written in Swift with a simple, declarative API in mind. // moves box to 100,100 with default settings anim { self.bo

Animation library for iOS in Swift
Animation library for iOS in Swift

TweenKit TweenKit is a powerful animation library that allows you to animate (or 'tween') anything. TweenKit's animations are also scrubbable, perfect

Comments
Owner
Robin Falko
Robin Falko
Wave is a spring-based animation engine for iOS that makes it easy to create fluid, interruptible animations that feel great.

Wave is a spring-based animation engine for iOS and iPadOS. It makes it easy to create fluid, interactive, and interruptible animations that feel great.

Janum Trivedi 1.2k Jan 8, 2023
A Fast Animation Engine with an Intuitive API

Kinieta An Animation Engine for iOS with an Intuitive API and Readable Code! (Written in Swift 4.0.) Why another? I decided to build an Animation Engi

Michael Michailidis 44 Sep 22, 2022
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Shohei Yokoyama 3k Dec 27, 2022
Pulse animation for iOS written with Swift.

Pulsator Pulse animation for iOS written with Swift. Great For: Pulses of Bluetooth, BLE, beacons (iBeacon), etc. Map Annotations Installation CocoaPo

Shuichi Tsutsumi 1.3k Jan 6, 2023
Various view's effects for iOS, written in Swift. Allows you to animate views nicely with easy to use extensions

Various view's effects for iOS, written in Swift. Allows you to animate views nicely with easy to use extensions. Every animation is randomized. Currently supported animations:

Artur Rymarz 23 Aug 23, 2022
SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift.

SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift ?? Demo There are 5 types of animation for component. border borde

Shohei Yokoyama 126 Oct 28, 2021
A slider widget with a popup bubble displaying the precise value selected written on Swift.

A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022
Fully customizable circular progress bar written in Swift.

Fully customizable, circular progress bar written in Swift. Example To run the example project, clone the repo, and run pod install from the Example d

Lionheart Software 137 Nov 11, 2022
TRightImageButton is a simple and flexible UI component fully written in Swift.

TRightImageButton is a simple and flexible UI component fully written in Swift. TRightImageButton is developed to help programmers create a button with right image quickly without having to write many lines of codes.

Nguyen Duc Thinh 2 Aug 18, 2022
TTouchAnimatedButton is a simple and flexible animation component fully written in Swift

TTouchAnimatedButton is a simple and flexible animation component fully written in Swift. TTouchAnimatedButton is developed to make user feel button click becomes more vivid and realistic.

Nguyen Duc Thinh 2 Aug 18, 2022