Skip to content

Instantly share code, notes, and snippets.

@stepheng
Created November 15, 2016 20:48
Show Gist options
  • Save stepheng/952e00e33ac83756dc920d7dcc94c057 to your computer and use it in GitHub Desktop.
Save stepheng/952e00e33ac83756dc920d7dcc94c057 to your computer and use it in GitHub Desktop.
import UIKit
enum StoryboardIdentifier: String {
case splashViewController
case mainMenuViewController
case levelSelectViewController
case optionsViewController
case gameViewController
}
fileprivate extension UIStoryboard {
func instantiateAppViewController(withIdentifier identifier: StoryboardIdentifier) -> UIViewController {
return instantiateViewController(withIdentifier: identifier.rawValue)
}
}
fileprivate class NavigationAssistant {
private static let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
private static var splashViewController: SplashViewController {
return mainStoryboard.instantiateAppViewController(withIdentifier: .splashViewController) as! SplashViewController
}
private static var mainMenuViewController: MainMenuViewController {
return mainStoryboard.instantiateAppViewController(withIdentifier: .mainMenuViewController) as! MainMenuViewController
}
private static var levelSelectViewController: LevelSelectViewController {
return mainStoryboard.instantiateAppViewController(withIdentifier: .levelSelectViewController) as! LevelSelectViewController
}
private static var optionsViewController: OptionsViewController {
return mainStoryboard.instantiateAppViewController(withIdentifier: .optionsViewController) as! OptionsViewController
}
private static var gameViewController: GameViewController {
return mainStoryboard.instantiateAppViewController(withIdentifier: .gameViewController) as! GameViewController
}
fileprivate static func viewController(forIdentifier identifier: StoryboardIdentifier) -> UIViewController {
switch identifier {
case .splashViewController:
return splashViewController
case .mainMenuViewController:
return mainMenuViewController
case .levelSelectViewController:
return levelSelectViewController
case .optionsViewController:
return optionsViewController
case .gameViewController:
return gameViewController
}
}
}
extension UIViewController {
func crossDissolve(toIdentifier identifier: StoryboardIdentifier) {
let viewController = NavigationAssistant.viewController(forIdentifier: identifier)
viewController.modalPresentationStyle = .fullScreen
viewController.modalTransitionStyle = .crossDissolve
show(viewController, sender: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment