I want to change tab through code with animation. Exact scenario is that there are 2 tabs with below hierarchy.
First tab
- Navigation controller
- Log
try this
- (void)logoutButtonPressed
{
// Go to root controller in navigation controller of first tab.
[self.navigationController popToRootViewControllerAnimated:YES];
NSArray *tabViewControllers = self.tabBarController.viewControllers;
UIView * fromView = self.tabBarController.selectedViewController.view;
UIView * toView = self.view;
NSUInteger fromIndex = [tabViewControllers indexOfObject:self.tabBarController.selectedViewController];
NSUInteger toIndex = [tabViewControllers indexOfObject:self];
[UIView transitionFromView:fromView
toView:toView
duration:0.3
options: toIndex > fromIndex ? UIViewAnimationOptionTransitionFlipFromLeft : UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
self.tabBarController.selectedIndex = 0;
}];
}