Search code examples
iosswiftanimationviewwilldisappear

ViewDisappear animation before tabbar click


I have a TabBarController that has 3 navigationController, where each has a corresponding viewController: AViewController, BViewController and CViewController. First one has a UIView element that I want to run animation against it when viewDisappears using:

UIView.animateWithDuration(duration, delay: 0.0, options: .CurveEaseOut, animations: {

during...

override func viewWillDisappear(animated: Bool) {

If user clicks on item 2 or 3 in the tabbar, I want that animation to take place first and then take the user to the item #2 or #3.

Problem is that that when user clicks a different item, this code in the TabBarController is triggered first before the viewwillDisappears in my ViewController A

override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {

and then my animation doesn't run.

Where should I place my animation so it runs before user is taken to a different item in the tabbar?


Solution

  • You could implement tabBarController:shouldSelectViewController: from UITabBarControllerDelegate, return false, play your animation and then programatically change tab.