-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Michael Michailidis edited this page Oct 31, 2017
·
5 revisions
Welcome to the kinieta Wiki!
An extension on UIView
that is included in the code will provide the entry point for the animations. The interface object is the Kinieta
and there is one for every view.
// This will snap the view to the given coordinates
aView.move(to: ["x": 250, "y": 500])
// This will animate the same view to the coordinates in 0.5 seconds
aView.move(to: ["x": 250, "y": 500], during: 0.5)
// This will delay the start of the animation by 0.5 seconds
aView.move(to: ["x": 250, "y": 500], during: 0.5).delay(for: 0.5)
// And this will ease the whole thing
aView.move(to: ["x": 250, "y": 500], during: 0.5).delay(for: 0.5).easeInOut()
// While this will ease it with a bounce-back
aView.move(to: ["x": 250, "y": 500], during: 0.5).delay(for: 0.5).easeInOut(.Back)
// And call the complete block when the animation is finished
aView.move(to: ["x": 250, "y": 500], during: 0.5).delay(for: 0.5).easeInOut(.Back).complete { print("♥") }
Every move can be smoothed by calling one of the 3 easing functions and pass:
// When no curve is passed `.Quad` is used
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeIn()
// Ease at start, end and both ends respectively
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeIn(.Cubic)
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeOut(.Cubic)
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeInOut(.Cubic)
You can string a few animations together very easily:
let start = ["x": aView.x, "y": aView.y]
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeInOut(.Cubic)
.move(to: ["x": 300, "y": 200], during: 0.5).easeInOut(.Cubic)
.move(to: start, during: 0.5).easeInOut(.Cubic)
The dictionary with the animations can be saved and passed later as the example above shows. You can also add a pause between animations by calling the wait(for time: TimeInterval)
function:
aView.move(to: ["x": 250, "y": 500], during: 0.5).easeInOut(.Cubic)
.wait(for: 0.5)
.move(to: ["x": 300, "y": 200], during: 0.5).easeInOut(.Cubic)
You can run various animations together to achieve more complicated effects. For example, we can add a short fade at the end of a move and have a single callback when everything finishes:
aView.move(to: ["x": 200, "y": 500], during: 1.0).easeInOut(.Cubic)
.move(to: ["a": 0], during: 0.2).delay(for: 0.8).easeOut()
.parallel()
.complete { print("Finished All") }