Elastic
Fancy elastic transition powered by Metal, UIKit Dynamics, & Hero:
Just a proof of concept inspired by รlvaro Carreras's Slide Concept. Not really optimized and does not support older devices. You should not use this in production. If you want something similar, checkout ElasticTransition
Supports UINavigationController, UITabBarController, & Modal Present. Since it is powered by Hero, the other views can still benefit from animations constructed by Hero.
Requirements
- Xcode 8.2
- Swift 3.0.2
- Metal compatible devices (iPhone 5s or newer)
Won't work on simulator.
Installation
pod "Elastic"
Usage
override func viewDidLoad() {
super.viewDidLoad()
// 1. Enable the plugin
ElasticHeroPlugin.isEnabled = true
// 2. setup a gesture recognizer
let leftGR = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(pan(gr:)))
leftGR.edges = UIRectEdge.left
view.addGestureRecognizer(leftGR)
// 3. set the heroModifier of the elastic view to be
view.heroModifiers = [.elastic(edge: .left, gestureRecognizer: leftGR)]
}
func pan(gr:UIScreenEdgePanGestureRecognizer){
if gr.state == .began {
// 4. perform your transition when the gesture recognizer begans. the rest will be handled automatically
performSegue(withIdentifier: "next", sender: nil)
}
}
The elastic view doesn't have to be the gesture recognizer's view. For example, the following code makes the next view controller's view elastic.
// This replaces step 3
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc = segue.destination
vc.view.heroModifiers = [.elastic(edge: .right, gestureRecognizer: rightGR)]
}
License
Elastic is available under the MIT license. See the LICENSE file for more info.