react-native-navigation的迁移库

UITabBarController+RNNOptions.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #import "UITabBarController+RNNOptions.h"
  2. #import "RNNBottomTabsController.h"
  3. #import "UITabBar+utils.h"
  4. @implementation UITabBarController (RNNOptions)
  5. - (void)setCurrentTabIndex:(NSUInteger)currentTabIndex {
  6. [self setSelectedIndex:currentTabIndex];
  7. }
  8. - (void)setCurrentTabID:(NSString *)currentTabId {
  9. [(RNNBottomTabsController*)self setSelectedIndexByComponentID:currentTabId];
  10. }
  11. - (void)setTabBarTestID:(NSString *)testID {
  12. self.tabBar.accessibilityIdentifier = testID;
  13. }
  14. - (void)setTabBarStyle:(UIBarStyle)barStyle {
  15. self.tabBar.barStyle = barStyle;
  16. }
  17. - (void)setTabBarTranslucent:(BOOL)translucent {
  18. self.tabBar.translucent = translucent;
  19. }
  20. - (void)setTabBarHideShadow:(BOOL)hideShadow {
  21. self.tabBar.clipsToBounds = hideShadow;
  22. }
  23. - (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated {
  24. const CGRect tabBarFrame = self.tabBar.frame;
  25. const CGRect tabBarVisibleFrame = CGRectMake(tabBarFrame.origin.x,
  26. self.view.frame.size.height - tabBarFrame.size.height,
  27. tabBarFrame.size.width,
  28. tabBarFrame.size.height);
  29. const CGRect tabBarHiddenFrame = CGRectMake(tabBarFrame.origin.x,
  30. self.view.frame.size.height,
  31. tabBarFrame.size.width,
  32. tabBarFrame.size.height);
  33. if (!animated) {
  34. self.tabBar.hidden = !visible;
  35. self.tabBar.frame = visible ? tabBarVisibleFrame : tabBarHiddenFrame;
  36. return;
  37. }
  38. static const CGFloat animationDuration = 0.15;
  39. if (visible) {
  40. self.tabBar.hidden = NO;
  41. [UIView animateWithDuration: animationDuration
  42. delay: 0
  43. options: UIViewAnimationOptionCurveEaseOut
  44. animations:^()
  45. {
  46. self.tabBar.frame = tabBarVisibleFrame;
  47. }
  48. completion:^(BOOL finished)
  49. {}];
  50. } else {
  51. [UIView animateWithDuration: animationDuration
  52. delay: 0
  53. options: UIViewAnimationOptionCurveEaseIn
  54. animations:^()
  55. {
  56. self.tabBar.frame = tabBarHiddenFrame;
  57. }
  58. completion:^(BOOL finished)
  59. {
  60. self.tabBar.hidden = YES;
  61. }];
  62. }
  63. }
  64. - (void)centerTabItems {
  65. [self.tabBar centerTabItems];
  66. }
  67. - (void)forEachTab:(void (^)(UIView *, UIViewController * tabViewController, int tabIndex))performOnTab {
  68. int tabIndex = 0;
  69. for (UIView * tab in self.tabBar.subviews) {
  70. if ([NSStringFromClass([tab class]) isEqualToString:@"UITabBarButton"]) {
  71. performOnTab(tab, [self childViewControllers][(NSUInteger) tabIndex], tabIndex);
  72. tabIndex++;
  73. }
  74. }
  75. }
  76. @end