Skip to content

Instantly share code, notes, and snippets.

@fastboatster
Created October 8, 2018 01:24
Show Gist options
  • Save fastboatster/bd538a370bee1082accb0f9deb465d1a to your computer and use it in GitHub Desktop.
Save fastboatster/bd538a370bee1082accb0f9deb465d1a to your computer and use it in GitHub Desktop.
import UIKit
extension UINavigationController {
/**
It removes all view controllers from navigation controller then set the new root view controller and it pops.
- parameter vc: root view controller to set a new
*/
func initRootViewController(vc: UIViewController, transitionType type: String = kCATransitionFade, duration: CFTimeInterval = 0.3) {
self.addTransition(transitionType: type, duration: duration)
self.viewControllers.removeAll()
self.pushViewController(vc, animated: false)
self.popToRootViewController(animated: false)
}
/**
It adds the animation of navigation flow.
- parameter type: kCATransitionType, it means style of animation
- parameter duration: CFTimeInterval, duration of animation
*/
private func addTransition(transitionType type: String = kCATransitionFade, duration: CFTimeInterval = 0.3) {
let transition = CATransition()
transition.duration = duration
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = type
self.view.layer.add(transition, forKey: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment