Guest User

Untitled

a guest
Jul 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. - (void) addTabBarArrow
  2. {
  3. UIImage* tabBarArrowImage = [UIImage imageNamed:@"TabBarNipple.png"];
  4. self.tabBarArrow = [[[UIImageView alloc] initWithImage:tabBarArrowImage] autorelease];
  5. CGRect frame = CGRectMake([self horizontalLocationFor:0], -4, [tabBarArrow frame].size.width, [tabBarArrow frame].size.height);
  6. [tabBarArrow setFrame:frame];
  7. [[tabBarController tabBar] addSubview:tabBarArrow];
  8.  
  9. }
  10.  
  11. - (CGFloat) horizontalLocationFor:(NSUInteger)tabIndex
  12. {
  13. UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
  14.  
  15. if (deviceOrientation == UIDeviceOrientationLandscapeRight || deviceOrientation == UIDeviceOrientationLandscapeLeft) {
  16. NSLog(@"land");
  17. // A single tab item's width is the entire width of the tab bar divided by number of items
  18. CGFloat tabItemWidth = 480 / tabBarController.tabBar.items.count;
  19. // A half width is tabItemWidth divided by 2 minus half the width of the arrow
  20. CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
  21.  
  22. // The horizontal location is the index times the width plus a half width
  23. return (tabIndex * tabItemWidth) + halfTabItemWidth;
  24. }else {
  25. NSLog(@"Portrait");
  26. // A single tab item's width is the entire width of the tab bar divided by number of items
  27. CGFloat tabItemWidth = 320 / tabBarController.tabBar.items.count;
  28. // A half width is tabItemWidth divided by 2 minus half the width of the arrow
  29. CGFloat halfTabItemWidth = (tabItemWidth / 2.0) - (tabBarArrow.frame.size.width / 2.0);
  30.  
  31. // The horizontal location is the index times the width plus a half width
  32. return (tabIndex * tabItemWidth) + halfTabItemWidth;
  33.  
  34. }
  35. }
  36.  
  37. - (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController
  38. {
  39. [UIView beginAnimations:nil context:nil];
  40. [UIView setAnimationDuration:0.2];
  41. CGRect frame = tabBarArrow.frame;
  42. frame.origin.x = [self horizontalLocationFor:tabBarController.selectedIndex];
  43. tabBarArrow.frame = frame;
  44. [UIView commitAnimations];
  45.  
  46. }
  47.  
  48. - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
  49. {
  50. NSLog(@"oi");
  51. [UIView beginAnimations:nil context:nil];
  52. [UIView setAnimationDuration:0.5];
  53. CGRect frame = tabBarArrow.frame;
  54. frame.origin.x = [self horizontalLocationFor:tabBarController.selectedIndex];
  55. tabBarArrow.frame = frame;
  56. [UIView commitAnimations];
  57. }
Add Comment
Please, Sign In to add comment