/TRX

Squeeze, chain, overlap, seek. A powerful swift animation framework

Primary LanguageSwiftMIT LicenseMIT

TRX

Build Status CocoaPods License

TRX is a versatile animation framework built with ease of use, powerful features and performance in mind. TRX is inspired by the the excellent JavaScript animation framework GSAP.

Key Features

  • Animate any numerical value
  • Chain, overlap and group Tweens into Timelines
  • Squeeze and stretch Tweens and Timelines
  • Have total control, pause, play, seek any Tween or Timeline

Examples

Tricks

Have a look at Tricks the example app.

Using TRX

Basic Usage

Tween any value

Tween(from: 0, to: 20, time: 0.3) {
  object.value = $0
}.start()

or neater...

1.trxTo(20) { object.value = $0 }.start()

Tween Double, CGFloat, CGPoint, CGSize, CGRect or even your own type (by extending the Morphable Protocol)

Tween(from: CGPointZero, to: CGPoint(x: 20, y: 15), time: 0.3) {
  layer.position = $0
}.start()

Use optional parameters for fine grained control

Tween(from: 0,
      to: 1,
      time: 0.3,
      delay: 0.1,
      ease: Ease.Elastic.easeOut,
      key: "MyOwnKey",
      onStart: { print("start") },
      onComplete: { done in print("complete and done: \(done)") }) { value in
    object.value = value
}.start()
  • from: Starting value (Morphable).
  • to: End value (Morphable).
  • time: Duration (NSTimeInterval).
  • delay: optional Time offset (NSTimeInterval). Defaults to 0.
  • ease: optional Timing function (Ease.TimingFunction). Defaults to Ease.Quad.easeOut.
  • key: optional Tween key (String). Any other running animation with the same key will be stopped. Defaults to nil.
  • onStart: optional Start callback. Defaults to nil.
  • onComplete: optional Completion callback. Defaults to nil.
  • update: Update callback

Timelines

Use a Timeline to chain Tweens or even other timelines

TimeLine(tweens: [
  1.trxTo(20) { object.value = $0 },
  30.trxTo(40) { object.value = $0 },
  ]).start()

Add tween with an overlap

let timeline = TimeLine()
timeline.add(1.trxTo(20) { object.value = $0 })
timeline.add(30.trxTo(40) { anOtherObject.value = $0 }, shift: -0.5)
timeline.start()

Squeeze and stretch tweens or timelines

let tween = Tween(from: 0, to: 1, time: 0.5) { print($0) }

tween.scale = 2 // duration: 1s
timeline.duration = 2.0 // scale: 4

UIView integration

Move to a new position

myView.trxCenterTo(CGPoint(x: 10, y: 15))

Move from a position to the current one

myView.trxCenterFrom(CGPointZero)

Animate frame to a given CGRect

myView.trxFrameTo(newFrame)

Animate frame from a given CGRect to the current frame

myView.trxFrameTo(someFrame)

Requirements

iOS: 8.4, tvOS: 9.0, Swift

Installation

Cocoa Pods

pod "TRX"

Don't forget to add use_frameworks! to the Podfile. Requires CocoaPods 0.36.x or greater. If you need more help use CocoaPods Guides.

Carthage

Add to your Cartfile:

github "Trxy/TRX"

Swift Package Manager (Experimental)

Specify a dependency in Package.swift

...
.Package(url: "https://github.com/Trxy/TRX.git", majorVersion: 0, minor: 2),
...

Manual

  1. Download or clone the project
  2. Build the the preferred target (eg. TRX iOS)
  3. Locate the framework in finder (from the products group) file and add it to your project.
  4. Add the framework as a dependency of your target in Build Phases
  5. Add the framework to “Link Binary with Libraries” and in the “General” tab under “Embedded Binaries”
  6. In order to distribute your app you need to build it for all possible architectures (armv7, armv7s, arm64, x86, etc)

Contributions

Contributions and suggestions are welcome!

If you find any problems using TRX feel free to create an issue. Don't forget to add a detailed description and steps to reproduce.

If you'd like to ask a general question use Stack Overflow with tag trx.swift.

License

MIT

Contributors: