Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void) addTabBarArrow
- {
- UIImage* tabBarArrowImage = [UIImage imageNamed:@"TabBarNipple.png"];
- self.tabBarArrow = [[[UIImageView alloc] initWithImage:tabBarArrowImage] autorelease];
- CGRect frame = CGRectMake([self horizontalLocationFor:0], -4, [tabBarArrow frame].size.width, [tabBarArrow frame].size.height);
- [tabBarArrow setFrame:frame];
- [[tabBarController tabBar] addSubview:tabBarArrow];
- }
- - (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex
- {
- UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
- if (deviceOrientation == UIDeviceOrientationLandscapeRight || deviceOrientation == UIDeviceOrientationLandscapeLeft) {
- NSLog(@"land");
- // A single tab item's width is the entire width of the tab bar divided by number of items
- CGFloat tabItemWidth = 480 / tabBarController.tabBar.items.count;
- // A half width is tabItemWidth divided by 2 minus half the width of the arrow
- CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
- // The horizontal location is the index times the width plus a half width
- return (tabIndex * tabItemWidth) + halfTabItemWidth;
- }else {
- NSLog(@"Portrait");
- // A single tab item's width is the entire width of the tab bar divided by number of items
- CGFloat tabItemWidth = 320 / tabBarController.tabBar.items.count;
- // A half width is tabItemWidth divided by 2 minus half the width of the arrow
- CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
- // The horizontal location is the index times the width plus a half width
- return (tabIndex * tabItemWidth) + halfTabItemWidth;
- }
- }
- - (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController
- {
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.2];
- CGRect frame = tabBarArrow.frame;
- frame.origin.x = [self horizontalLocationFor:tabBarController.selectedIndex];
- tabBarArrow.frame = frame;
- [UIView commitAnimations];
- }
- - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
- {
- NSLog(@"oi");
- [UIView beginAnimations:nil context:nil];
- [UIView setAnimationDuration:0.5];
- CGRect frame = tabBarArrow.frame;
- frame.origin.x = [self horizontalLocationFor:tabBarController.selectedIndex];
- tabBarArrow.frame = frame;
- [UIView commitAnimations];
- }
Add Comment
Please, Sign In to add comment