ElasticTransition
A UIKit custom transition that simulates an elastic drag. Written in Swift.
Top Related Projects
A custom reusable circular / progress slider control for iOS application.
:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion
:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion
Animated side menu with customizable UI
:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
:octocat: PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion
Quick Overview
ElasticTransition is an iOS library that provides a custom transition animation between view controllers. It creates a smooth, elastic-like effect when transitioning between screens, enhancing the user experience with visually appealing animations.
Pros
- Easy to implement with minimal code changes
- Highly customizable with various animation parameters
- Supports both push/pop and modal transitions
- Compatible with both Swift and Objective-C projects
Cons
- Limited to iOS platform only
- May not be suitable for all types of applications or design styles
- Requires iOS 8.0 or later
- Not actively maintained (last update was in 2017)
Code Examples
- Basic usage for push transition:
let transition = ElasticTransition()
navigationController?.delegate = transition
navigationController?.pushViewController(viewController, animated: true)
- Customizing transition properties:
let transition = ElasticTransition()
transition.edge = .right
transition.sticky = true
transition.radiusFactor = 0.5
transition.shadowColor = .black
- Using with modal presentation:
let transition = ElasticTransition()
viewController.transitioningDelegate = transition
present(viewController, animated: true, completion: nil)
Getting Started
- Install ElasticTransition using CocoaPods by adding the following to your Podfile:
pod 'ElasticTransition'
- Import the library in your Swift file:
import ElasticTransition
- Create an instance of ElasticTransition and set it as the delegate for your navigation controller or as the transitioning delegate for modal presentations:
let transition = ElasticTransition()
navigationController?.delegate = transition
// or
viewController.transitioningDelegate = transition
- Customize the transition properties as needed:
transition.edge = .left
transition.sticky = true
transition.radiusFactor = 0.8
- Perform the transition using standard UIKit methods:
navigationController?.pushViewController(viewController, animated: true)
// or
present(viewController, animated: true, completion: nil)
Competitor Comparisons
A custom reusable circular / progress slider control for iOS application.
Pros of HGCircularSlider
- Focused on circular slider functionality, providing a specific and refined user interface element
- Offers customizable appearance and behavior for circular sliders
- Lightweight and easy to integrate into iOS projects
Cons of HGCircularSlider
- Limited to circular slider functionality, less versatile than ElasticTransition
- May require additional components for complex UI transitions or animations
- Less active development and community engagement compared to ElasticTransition
Code Comparison
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .left
transition.sticky = true
viewController.transitioningDelegate = transition
HGCircularSlider:
let circularSlider = CircularSlider(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
circularSlider.minimumValue = 0.0
circularSlider.maximumValue = 100.0
circularSlider.endPointValue = 50.0
view.addSubview(circularSlider)
Summary
ElasticTransition is a versatile animation library for iOS transitions, while HGCircularSlider focuses specifically on circular slider functionality. ElasticTransition offers more flexibility for various UI transitions, whereas HGCircularSlider provides a refined solution for circular sliders. The choice between the two depends on the specific requirements of your project and the desired user interface elements.
:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion
Pros of folding-cell
- Specialized for creating expandable cell animations in iOS
- Provides a more specific and tailored solution for folding cell UI
- Easier to implement for its specific use case
Cons of folding-cell
- Limited to iOS platform, while ElasticTransition supports both iOS and tvOS
- Less versatile compared to ElasticTransition's broader transition capabilities
- May require more custom work for non-standard cell designs
Code Comparison
folding-cell:
let cell = FoldingCell()
cell.itemCount = 4
cell.backgroundColor = .clear
cell.setup(name: "Cell", duration: 0.8, backViewColor: .brown)
tableView.insertSubview(cell, at: 0)
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .right
transition.sticky = true
transition.panThreshold = 0.3
viewController.transitioningDelegate = transition
present(viewController, animated: true, completion: nil)
Both libraries offer unique animation capabilities, but folding-cell is more focused on a specific UI element, while ElasticTransition provides a broader range of transition effects. The choice between them depends on the specific requirements of your iOS application and the desired user interface elements.
:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion
Pros of expanding-collection
- More focused on a specific UI pattern (expanding cards collection)
- Provides a complete, ready-to-use UI component
- Includes detailed documentation and usage examples
Cons of expanding-collection
- Less flexible for general-purpose transitions
- May require more customization for non-standard use cases
- Limited to iOS platform (Swift)
Code Comparison
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .right
transition.sticky = true
transition.panThreshold = 0.3
viewController.customTransition = transition
expanding-collection:
let viewController = ExpandingViewController(style: .cards)
viewController.itemSize = CGSize(width: 256, height: 335)
viewController.collectionView?.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
let nib = UINib(nibName: "DemoCell", bundle: nil)
viewController.registerNib(nib, forCellWithReuseIdentifier: "cell")
Summary
ElasticTransition offers a more general-purpose transition framework with elastic animations, while expanding-collection provides a specific UI component for card-based collections. ElasticTransition is more flexible but requires more setup, whereas expanding-collection offers a ready-to-use solution for its specific use case. The choice between the two depends on the project requirements and desired UI patterns.
Animated side menu with customizable UI
Pros of Side-Menu.iOS
- Specifically designed for iOS side menu implementation
- Provides a customizable and animated side menu out of the box
- Easy to integrate with existing iOS projects
Cons of Side-Menu.iOS
- Limited to side menu functionality, less versatile for other transition types
- May require more customization for complex menu designs
- Less active maintenance and updates compared to ElasticTransition
Code Comparison
Side-Menu.iOS:
let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
SideMenuManager.default.leftMenuNavigationController = menuLeftNavigationController
SideMenuManager.default.addPanGestureToPresent(toView: self.navigationController!.navigationBar)
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .left
transition.sticky = true
viewController.transitioningDelegate = transition
present(viewController, animated: true, completion: nil)
ElasticTransition offers a more flexible approach for various transition types, while Side-Menu.iOS provides a more specialized solution for side menus in iOS applications. ElasticTransition's code is more concise and adaptable to different scenarios, whereas Side-Menu.iOS requires less setup for implementing a standard side menu. The choice between the two depends on the specific project requirements and desired customization level.
:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
Pros of animated-tab-bar
- Focuses specifically on tab bar animations, providing a polished and specialized solution
- Offers a variety of pre-built animation styles for quick implementation
- Actively maintained with recent updates and contributions
Cons of animated-tab-bar
- Limited to tab bar animations, less versatile for other transition effects
- Requires more setup and configuration for custom animations
- Larger file size due to included animation assets
Code Comparison
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .right
transition.sticky = true
viewController.transitioningDelegate = transition
present(viewController, animated: true, completion: nil)
animated-tab-bar:
let tabBarController = RAMAnimatedTabBarController()
let item1 = RAMAnimatedTabBarItem(title: "Home", image: UIImage(named: "home"), tag: 1)
item1.animation = RAMBounceAnimation()
tabBarController.viewControllers = [vc1, vc2, vc3]
tabBarController.setViewControllers([vc1, vc2, vc3], animated: true)
Both libraries offer unique transition animations, but ElasticTransition provides a more general-purpose solution for various view transitions, while animated-tab-bar specializes in enhancing tab bar interactions with pre-built animations.
:octocat: PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion
Pros of paper-onboarding
- Specifically designed for onboarding experiences, providing a more focused solution
- Offers a visually appealing paper-like animation effect
- Includes built-in support for customizable content and icons
Cons of paper-onboarding
- Limited to onboarding scenarios, less versatile than ElasticTransition
- May require more setup for complex transitions between views
Code Comparison
ElasticTransition:
let transition = ElasticTransition()
transition.edge = .right
transition.sticky = true
viewController.transitioningDelegate = transition
paper-onboarding:
let onboarding = PaperOnboarding()
onboarding.dataSource = self
onboarding.delegate = self
view.addSubview(onboarding)
ElasticTransition provides a more general-purpose transition framework, allowing for various edge-based transitions with elastic effects. It's suitable for different types of view transitions throughout an app.
paper-onboarding, on the other hand, is tailored specifically for creating onboarding experiences with a unique paper-like animation. It offers a more streamlined setup for this particular use case but is less flexible for other transition scenarios.
The choice between these libraries depends on the specific needs of your project. If you're focusing on creating an engaging onboarding experience, paper-onboarding might be the better choice. For more versatile transition effects throughout your app, ElasticTransition could be more suitable.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ElasticTransition (Swift 3)
A UIKit custom modal transition that simulates an elastic drag. Written in Swift.
###Thanks to Matt Garnett (@c-o-l-o-r) for converting ElasticTransition to Swift 3
###Also, special thanks to @taglia3 for developing the [Objective-C version] (https://github.com/taglia3/ElasticTransition-ObjC). Check it out!
Requirements
- Xcode 8 or higher
- iOS 8.0 or higher
- Swift 3.0
Installation
####CocoaPods
use_frameworks!
pod "ElasticTransition"
Usage
Simple
import ElasticTransition
// make your view controller a subclass of ElasticModalViewController
// present it as normal
class YourModalViewController:ElasticModalViewController{
// ...
}
class RootViewController:UIViewController{
// ...
@IBAction func modalBtnTouched(sender: AnyObject) {
performSegueWithIdentifier("modalSegueIdentifier", sender: self)
// or if you want to do customization ---------------------
let modalViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("modalViewControllerIdentifier") as! YourModalViewController
// customization:
modalViewController.modalTransition.edge = .Left
modalViewController.modalTransition.radiusFactor = 0.3
// ...
presentViewController(modalViewController, animated: true, completion: nil)
}
}
Attributes you can set:
// screen edge of the transition
public var edge:Edge
// animation stiffness - determines the speed of the animation
public var stiffness:CGFloat = 0.2
// animation damping - determines the bounciness of the animation
public var damping:CGFloat = 0.2
// Background view transform
public var transformType:ElasticTransitionBackgroundTransform = .TranslateMid
// The curvature of the elastic edge.
public var radiusFactor:CGFloat = 0.5
/**
Determines whether or not the view edge will stick to
the initial position when dragged.
**Only effective when doing a interactive transition**
*/
public var sticky:Bool = true
/**
The initial position of the simulated drag when static animation is performed
i.e. The static animation will behave like user is dragging from this point
**Only effective when doing a static transition**
*/
public var startingPoint:CGPoint?
/**
The background color of the container when doing the transition
*/
public var containerColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 1.0)
/**
The color of the overlay when doing the transition
*/
public var overlayColor:UIColor = UIColor(red: 152/255, green: 174/255, blue: 196/255, alpha: 0.5)
/**
Whether or not to display the shadow. Will decrease performance.
*/
public var showShadow:Bool = false
/**
The shadow color of the container when doing the transition
*/
public var shadowColor:UIColor = UIColor(red: 100/255, green: 122/255, blue: 144/255, alpha: 1.0)
/**
The shadow radius of the container when doing the transition
*/
public var shadowRadius:CGFloat = 50
Advance Usage
This work with any view controller.
In prepareForSegue, assign the transition to be the transitioningDelegate of the destinationViewController. Also, dont forget to set the modalPresentationStyle to .Custom
var transition = ElasticTransition()
override func viewDidLoad() {
super.viewDidLoad()
// customization
transition.edge = .Left
transition.sticky = false
// etc
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
segue.destinationViewController.transitioningDelegate = transition
segue.destinationViewController.modalPresentationStyle = .Custom
}
(Optional) In your modal view controller implement the ElasticMenuTransitionDelegate and provide the contentLength
class MenuViewController: UIViewController, ElasticMenuTransitionDelegate {
var contentLength:CGFloat = 320
// ...
}
Interactive transition for modal transition
First, construct a pan gesture recognizer
let panGR = UIPanGestureRecognizer(target: self, action: "handlePan:")
view.addGestureRecognizer(panGR)
Then implement your gesture handler and fo the following:
func handlePan(pan:UIPanGestureRecognizer){
if pan.state == .Began{
// Here, you can do one of two things
// 1. show a viewcontroller directly
let nextViewController = // construct your VC ...
transition.startInteractiveTransition(self, toViewController: nextViewController, gestureRecognizer: pan)
// 2. perform a segue
transition.startInteractiveTransition(self, segueIdentifier: "menu", gestureRecognizer: pan)
}else{
transition.updateInteractiveTransition(gestureRecognizer: pan)
}
}
Interactive transition for dismissing the modal
- Implement ElasticMenuTransitionDelegate in your modal view controller and set
var dismissByBackgroundTouch = true
var dismissByBackgroundDrag = true
var dismissByForegroundDrag = true
- Or use your own panGestureRecognizer and call dissmissInteractiveTransition in your handler
func handlePan(pan:UIPanGestureRecognizer){
if pan.state == .Began{
transition.dissmissInteractiveTransition(self, gestureRecognizer: pan, completion: nil)
}else{
transition.updateInteractiveTransition(gestureRecognizer: pan)
}
}
Author
Luke Zhao, me@lkzhao.com
License
ElasticTransition is available under the MIT license. See the LICENSE file for more info.
Top Related Projects
A custom reusable circular / progress slider control for iOS application.
:octocat: 📃 FoldingCell is an expanding content cell with animation made by @Ramotion
:octocat: ExpandingCollection is an animated material design UI card peek/pop controller. iOS library made by @Ramotion
Animated side menu with customizable UI
:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
:octocat: PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot