Skip to content

Instantly share code, notes, and snippets.

@venkatd
Created August 9, 2012 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venkatd/3308217 to your computer and use it in GitHub Desktop.
Save venkatd/3308217 to your computer and use it in GitHub Desktop.
Animate tabBarController custom
NSInteger controllerIndex = 2;
UIView *fromView = self.tabBarController.selectedViewController.view;
UIView *toView = [[self.tabBarController.viewControllers objectAtIndex:controllerIndex] view];
// Get the size of the view area.
CGRect viewSize = fromView.frame;
BOOL scrollRight = controllerIndex > self.tabBarController.selectedIndex;
// Add the to view to the tab bar view.
[fromView.superview addSubview:toView];
// Position it off screen.
toView.frame = CGRectMake((scrollRight ? 320 : -320), viewSize.origin.y, 320, viewSize.size.height);
[UIView animateWithDuration:0.3
animations: ^{
// Animate the views on and off the screen. This will appear to slide.
fromView.frame =CGRectMake((scrollRight ? -320 : 320), viewSize.origin.y, 320, viewSize.size.height);
toView.frame = CGRectMake(0, viewSize.origin.y, 320, viewSize.size.height);
}
completion:^(BOOL finished) {
if (finished) {
// Remove the old view from the tabbar view.
[fromView removeFromSuperview];
self.tabBarController.selectedIndex = controllerIndex;
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment