I am creating a title bar for my iOS application and I am making this inside a UIView. The only issue I am having is with the \"home button\". When the home button is presse
With Swift 4 - 4.2 Adding onto Shamsudheen TK's answer.
var topVC = UIApplication.shared.keyWindow?.rootViewController
while((topVC!.presentedViewController) != nil) {
topVC = topVC!.presentedViewController
}
let customViewController = CustomViewController()
topVC?.present(customViewController, animated: true, completion: nil)
With UINavigationController: Here is also an additional feature -> You can pass along a UINavigationController with your customViewController.
var topVC = UIApplication.shared.keyWindow?.rootViewController
while((topVC!.presentedViewController) != nil) {
topVC = topVC!.presentedViewController
}
let customViewController = CustomViewController()
let navController = UINavigationController(rootViewController: CustomViewController)
topVC?.present(navController, animated: true, completion: nil)