Introduction
Welcome to the documentation for JHChainableAnimations!
JHChainableAnimations is a library that allows you to easily chain multiple animations together to create complex and fluid animations for your iOS app. With this library, you can create smooth animation sequences with just a few lines of code.
Installation
To integrate JHChainableAnimations into your project, follow these steps:
- Install JHChainableAnimations through CocoaPods by adding it to your
Podfile
: - Run the command
pod install
to install the library. - Import the library in your Swift file:
pod 'JHChainableAnimations'
import JHChainableAnimations
Usage
To create chainable animations, you need to use the UIView+JHChainableAnimations
extension.
Basic Animation
To perform a basic animation, you can use the make
method followed by the animation you desire, such as .moveX
or .rotate
, and then call .animate
to apply the animation.
// Example: Move a view to the right by 100 points over 0.5 seconds
view.make(.moveX(100)).animateWithDuration(0.5).animate()
Chained Animation
You can chain animations together using the then
method. Each chained animation will be performed sequentially.
// Example: Move a view to the right, then rotate it, and finally change the background color
view.make(.moveX(100)).then(.rotate(90)).then(.backgroundColor(UIColor.red)).animate()
Callbacks
You can attach completion blocks to animations using the withCompletionBlock
method. This allows you to perform actions after the animation finishes.
// Example: Move a view to the right with a completion block
view.make(.moveX(100)).withCompletionBlock {
print("Animation finished!")
}.animate()
Resetting
You can reset the applied animations using the reset
method.
// Example: Reset all animations applied to a view
view.reset()
Additional Methods
The library provides additional methods to customize your animations:
.delay
: Adds a delay before the animation starts..easeIn
,.easeOut
,.easeInOut
: Specify the easing functions for the animation..spring
: Apply spring dynamics to the animation..repeat
: Repeat the animation specified number of times..thenAfter
: Performs the animation after the specified time interval..wait
: Waits for the specified time interval without animating..animateWithRepeat
: Apply an animation repeatedly.
Examples
Example 1: Move and Fade Animation
In this example, we will create a chainable animation to move and fade a view simultaneously.
view.make(.moveX(100)).and(.fadeOut).animate()
Example 2: Advanced Chained Animation
Here, we will perform a more complex chained animation that involves multiple transformations.
view.make(.moveX(100)).then(.rotateX(45)).then(.moveX(50)).then(.scale(2)).animate()
Conclusion
With JHChainableAnimations, you have the power to create fluid and impressive animations for your iOS app. Experiment with different animations and chaining techniques to achieve the desired effects. Enjoy animating!