Created
February 22, 2021 06:13
-
-
Save roz0n/82f12845d082c6b78399953816bf9b90 to your computer and use it in GitHub Desktop.
Presenting from detached view controllers in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIViewController extension to get root VC | |
func getRootViewController(of nestedViewController: UIViewController) -> UIViewController? { | |
return nestedViewController.view.window?.rootViewController | |
} | |
// In use inside non-root VC | |
let vc = UINavigationController(rootViewController: CurrencySelectorViewController(type: type)) | |
vc.modalPresentationStyle = .overFullScreen | |
if let root = getRootViewController(of: self) { | |
root.present(vc, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment