Created
August 9, 2012 21:30
-
-
Save venkatd/3308217 to your computer and use it in GitHub Desktop.
Animate tabBarController custom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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