Syed e Hussaini Syed e Hussaini - 1 month ago 5
iOS Question

Disable UITabBarController animation while setting rootViewContorller

I have a login screen and when user submit correct credentials i just change the root view controller of

window
to my
tabbarController

It shows a very abrupt animation like the screen is being bigger from top to bottom. I don't need any sort of animation when i logged in. How could i stop
UITabBarController
from being animate?

Here is the method in my
AppDelegate
which i used to login.

func userDidLoggedIn() -> Void {
tabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! VaboTabBarController


self.window?.rootViewController = self.tabBarController
self.window?.makeKeyAndVisible()

self.registerDeviceForPushNotification(UIApplication.sharedApplication())

}


In my
LoginViewController
when credentials are accurate i just use below code to switch to
TabBarController
.
Here is the code.

dispatch_async(dispatch_get_main_queue(), {
UIView.animateWithDuration(0.9, animations: {
let userDefault = NSUserDefaults.standardUserDefaults()
let array = parseJSON["userData"] as! NSArray
appDelegate.userDidLoggedIn()
})

Answer

You wrapped the presentation of the tabbarController into a UIView.animateWithDuration function.

And you display the tabbarcontroller with animation from the body of func userDidLoggedIn() function:

 self.window?.rootViewController = self.tabBarController
 self.window?.makeKeyAndVisible()

I think this is causing the weird animation. make the appDelegate.userDidLoggedIn() outside of the animateWithDuration function.