Similar to Instagram, my app shows Tabbar VC as the root VC if the user already has already logged in by checking NSUserDefault. I have the following code that deals with logout to go back to login screen
if LOGIN_SCREEN_SHOWN == true {
self.dismissViewControllerAnimated(true, completion: nil)
} else {
let loginVC = self.storyboard?.instantiateViewControllerWithIdentifier("LoginVC") as! LoginVC
self.presentViewController(loginVC, animated: true) {
//self.removeFromParentViewController()
self.tabBarController!.removeFromParentViewController()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = loginVC
LOGIN_SCREEN_SHOWN = true
}
}
Basically LOGIN_SCREEN_SHOWN is set to true in viewWillAppear in LoginVC indicating that we have been segue'd from LoginVC.
I have deInit code with print outs in all my VC. What I am finding is that if LOGINSCREENSHOWN == TRUE, dismissViewControllerAnimated is doing what I want to do and calling all the deInit code in all my VC printing out
NavVC Deinit Successfully
NavVC Deinit Successfully
NavVC Deinit Successfully
NavVC Deinit Successfully
VC1 Deinit Successfully
VC2 Deinit Successfully
VC3 Deinit Successfully
VC4 Deinit Successfully
However, the code under "else" where I present Login VC and attempt to remove VC from after LoginVC is presented does not give me the print out indicating that the code is not doing what I'd like it to do. Could someone please point me to the right direction
----UPDATE----
This is the final code that works from Ketan Parmar. I have modified the transition type and duration to mimic dismissViewControllerAnimated animation
if LOGIN_SCREEN_SHOWN == true {
self.dismissViewControllerAnimated(true, completion: nil)
} else {
// Custom transition
let transition : CATransition = CATransition()
transition.duration = 0.35
transition.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionReveal
transition.subtype = kCATransitionFromBottom
let loginVC = self.storyboard?.instantiateViewControllerWithIdentifier("LoginVC") as! LoginVC
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.layer.addAnimation(transition, forKey: nil)
appDelegate.window?.rootViewController = loginVC
LOGIN_SCREEN_SHOWN = true
}