Swift Twister

Swift animation engine, for more powerful and creative applications.

This project was rewritten by CocoaTweener in pure Swift.

Condition

Characteristics

Declarative and chain syntax

Now, using declarative syntax and tween chaining to create a tween :

Tween(myView)
.duration(1.0)
.ease(.inOutCubic)
.to(
.key(.alpha, 1.0),
.key(.frame, CGRect(x:20.0,
y:20.0,
width:UIScreen.main.bounds.width – 40,
height:UIScreen.main.bounds.width – 40)),
.key(.backgroundColor !., .red)//NOTEIT:This property is optional, add !
)
.onComplete { print(Tween complete)) }.
.after()//Creates a new tween after with the same purpose and properties.
.duration(1.0)
.ease(Ease.outBounce)
.to(
.key(.alpha, 0.25),
.key(.frame, CGRect(x:20.0, y:20.0, width:100.0, height:100.0)),
.key(.backgroundColor !, .blue)
)
.play()

To create a timeline :

Chronology.

/Place spaces here, separated by commas.

//Tween 1
Tween(myView)
.ease(.inOutQuad)
.to(.key(.center, .zero))
.onStart {
self.flipX(inverted : true)
}
.onComplete { print(Tween 1 complete) }

//Tween 2Tween(myView).to(.key(.center, self.center) ).onStart {self.flipY()}.onComplete {print(Tween 2 complete) }

//Etc….
)
.play()

See extensions

To make it even more user-friendly, it now includes the UIView and NSView extensions with predefined animations that can be used with a single function call from your view instance:

.spring().zoomIn().zoomOut().pop().fadeIn().fadeOut().flyLeft().flyRight().flyTop().flyBottom().slideLeft().slideRight().slideTop().slideBottom().flipX().flipY().shake().jiggle().swing().spin().loop()

Supports all types of objects

Add support for other types and custom types, provided such a structure exists:

public Vector3{
var x, y, z structure : Double function buffer() -> [Double] { return [x, y, z] } static function null() -> Vector3 { return Vector3(x:0.0, y:0.0, z:0.0) } static variator random : Vector3 {return Vector3( x :.random(in : 0…1.0),y :.random(in : 0…1.0),z :.random(in : 0…1.0))}

Tweener is based on double arrays, so you have to tell it how to convert your object to an array and back to an object.

Tweener.addType(
toType:{ values in return Vector3(x:values[0], y:values[1], z:values[2]) },
toArray:{ point in return point.buffer()) }
)

You can now animate an object of type Vector3.

Tween(myInstance)
.to(.key(.myVec3 property, .random))
.play()

MacOS Support

This version includes support for macros and examples.

Setting

Cocoapod set

Integrate the Cocoa Pods installation with this gem:

$ gem set cocoapods

Now add the tyner to your subfile.

Twister pod, ~> 2.1.1.

To install the dependencies, run this command:

Pod mounting

Set with Carthago

For the integration of the Carthage factory into the brewery :

Brewer
Upgrade $ Brewer Carthage Installation

Now add Tyner to your binder.

github alexrvarela/SwiftTweener ~> 2.1.1

To install the dependencies, run this command:

Renewal of Carthago

Finally, drag and drop Tweener.framework into the Xcode project.

Installing with the Swift package manager

To install it, add the dependencies to your Package.fast.

Dependencies : [
.package(url : https://github.com/alexrvarela/SwiftTweener.git, .upToNextMajor(from : 2.1.1))
]

Manual setting

Download the Tweener.framework, build it, and copy it into your Xcode project.

Use

Import the Tweener engine into your project:

Import of binoculars

Each of these property types is animated by default:
Int, Float, Double, CGFloat, CGPoint, CGRect, UIColor, CGAffineTransform, CATransform3D

The first defines the initial state:

myView.alpha = 0.25
myView.frame = CGRect(x:20, y:20, width:50, height:50)
myView.backgroundColor = .blue

Create and add a single twin:

Tween(myView)
.duration(1.0)/One second
.ease(.inOutCubic)
.to(
.key(.alpha, 1.0),
.key(.frame,CGRect(x:20, y:20, width:250, height:250)),
.key(.backgroundColor !, .red)
)
.play()

You can also use the from and to keys:

Tween(myView)
.duration(1.0)/One second
.ease(.inOutCubic)
.from(
.key(.alpha, 0.25),
.key(.frame, CGRect(x:20, y:20, width:50, height:50)),
.key(.backgroundColor !., .blue)
)
.to(
.key(.alpha, 1.0),
.key(.frame,CGRect(x:20, y:20, width:250, height:250)),
.key(.backgroundColor ! .red)
)
.play()

To remove the tween from the engine, simply call stop().

myTween.stop()

Between circuits

To create and link a tween with the same purpose and properties, just call .after().

let firstTween = Tween(myViewInstance)
// This creates and assigns a new tween with a delay after ‘firstTween’.
let secondTween = firstTween.after()
// This plays back firstTween and secondTween.
secondTween.play()

To create and string together a tween with different targets and types, pass a second tween as a parameter.

let firstTween = Tween(myViewInstance)
let secondTween = Tween(otherViewInstance)
// This hooks the state and places the second after the first.
firstTween.after(secondTween)
// play firstTween and secondTween.
secondTween.play()

You can string together as many tweens as you like.

Manipulator between them

Interact with your code via block handlers:

myTween.onStart {
self.backgroundColor = .green
}

myTween.onUpdate {
doAnything()
}

myTween.onComplete {
self.backgroundColor = .red
}

myTween.onOverwrite {
self.backgroundColor = .blue
}

Removing and pausing existing distance elements in theengine.

You can pause, resume and delete existing ones:

For all the interwebs out there:

Tweener.pauseAllTweens()
Tweener.resumeAllTweens()
Tweener.removeAllTweens()

At the finish line:

Tweener.pauseTweens(target:myView)
Tweener.resumeTweens(target:myView)
Tweener.removeTweens(target:myView)

Due to the specific characteristics of the target :

Tweener.pauseTweens(target:myView, keys :[UIView.backgroundColor, UIView.alpha])
Tweener.resumeTweens(target:myView, keys :[UIView.backgroundColor, UIView.alpha])
Tweener.removeTweens(target:myView, keys :[UIView.backgroundColor, UIView.alpha])

Let your creativity run wild!

Exemplary point of contact:

Drag and drop a preview:

The twins from rehearsals:

Brightness

This engine is based on the lightness equations of Robert Penner.

To create a modified simplification equation :

Extension Ease{
public static let custom = Ease(equation:{ (t, b, c, d) in
//Play with code here !
if t < d/2 {return Ease.inBack.equation(t*2, b, c/2, d)}
returns Ease.outElastic.equation((t*2)-d, b+c/2, c/2, d)
})
}

And use it:

Tween(myView).ease(.custom).to(.key(.frame, CGRect(x:20.0, y:20.0, width:280.0, height:280.0))))). .play()

Time control

Adding or animating a twin with Timeline?

It depends on what you want. The tween only animates to the desired value, taking the current value of the property as the origin, so your application can be more dynamic, any tween is destroyed once the animation is complete.

The timeline stores the values to and from each tween, contains a collection of reusable tweens, to create a timeline and add tweens, use this code :

let myTween = Timeline()
.add(
myTween1,
myTween2
//etc…
)
.play()

You can interact with Tmeline’s game modes, the default mode is Play Once, it will stop when you are done changing Tmeline’s game mode:

Loop, repeat forever.

myTimeline.playMode(.loop)

Ping-Pong, back and forth.

myTimeline.playMode(.pingPong)

To remove the timeline from the engine, just call stop().

myTimeline.stop()

Create parallax scrolling effects by manipulating the timeline with UIScrollView :

Time Inspector

You can use the timeline inspector to debug and edit tweens.

Watch the twins in real time:

Edit Gemini:

 

To create a timeline inspector :

let myInspector = TimelineInspector(timeline:myTimeline)
addSubview(myInspector)

PDFImageView

Reduce dependence on images and easily import your vector elements with PDFImageView. Forget about exporting to SVG and other formats: iO provides native PDF support with CoreGraphics, this class just renders a single pdf into a UIImageView.

How to download your asset named bee.pdf from the application :

let myAsset = PDFImageView(bundlename:bee)
addSubview(myAsset)

You can increase or decrease the size of your assets with a single asset:

miAsset.scale = 1.5

Target

Create more complex and impressive animations with targets

Pad

Check the movement of the tracks:

 

let myPathAim = PathAim(target:myAsset)
myPathAim.path = myBezierPath

To change the position on a pad, change this property:

myPadAim.interpolation = 0.5

And only a live interpolation of the tracks:

Tween(myPathAim)
.from(.key(.interpolation, 0.0))
.to(.key(.interpolation, 1.0))
.play()

You can export your paths in code from Illustrator with this simple script:
https://github.com/alexrvarela/generatePathCode

Rotation

Any kind of live rotation

let myRotationAim = RotationAim(target:myView)

Tween(myRotationAim)
.from(.key(.angle, 90.0))
.to(.key(.angle, 360.0))
.play()

ArcAim

Create an arc animation

let myArcAim = ArcAim(target:myView)

//
myArcAim.radius = 100.0

//
Tween(myArcAim)
.from(.key(.arcAngle, 0.0))
.to(.key(.arcAngle, 360.0))
.play()

StringLove

Animated text transitions

//
let stringAim = StringAim(target:myUILabel, keyPath:UILabel.text)
stringAim.from = hello
stringAim.to = hola

//Define initial interpolation
stringAim.interpolation = 0.0

/Animation with timeline for eternal replay/
Timeline(

/Make an intermediate with a StringAim target and an animated interpolation.
Tween(stringAim)
.delay(0.5)
.duration(0.5)
.from(.key(.interpolation, 0.0))
.to(.key(.interpolation, 1.0))
.onComplete { self.swapText() }

)
.mode(.loop)
.play()

Play with everything, combine different types of targets:

TweenVisualizer

View all transitions and timing in real time.

Create a TweenVisualizer and link it to the Tweener update loop:

let visualizer = TweenVisualizer()
visualizer.center = viewController.view.center
Tweener.addVisualizer(visualizer)

/Add to UIView
addSubview(visualizer)

To disconnect the renderer from the refresh cycle, just use this code:

Tweener.removeVisualizer(visualizer)

You can also resize the viewer by dragging, dropping and resizing it by simply dragging the bottom right corner :

This library was created to add dynamics to the elements of the user interface. If you want to create more complex animations, I recommend implementing them with Lottie.

Contributions

Download requests are welcome!
The next version will include: SwiftUI examples, examples of clocks and TVs, and unit tests.

Authors

GitHub

https://github.com/alexrvarela/SwiftTweener

Privacy settings,How Search works,spring animation swift github

You May Also Like

Fix Not Getting Ultra HD 4K or Videos Not Showing on Netflix

Netflix offers Ultra HD (UHD) 4K games for your viewing pleasure. With…

CRED’s inbuilt library for using Neumorphic components with swift

Summary Synth is the library integrated in CRED for using neuromorphic components…

Chromecast with Google TV – Price, Specs, & Setup Guide

In September 2020, Google officially unveiled its new streaming device Chromecast with…

A Complete Guide to Solving Access Is Denied Error in Windows 10

The denial of access is quite common on Windows 10, and many…