react-native-navigation的迁移库

UITabBarController+RNNOptions.m 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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)setTabBarBackgroundColor:(UIColor *)backgroundColor {
  15. self.tabBar.barTintColor = backgroundColor;
  16. }
  17. - (void)setTabBarStyle:(UIBarStyle)barStyle {
  18. self.tabBar.barStyle = barStyle;
  19. }
  20. - (void)setTabBarTranslucent:(BOOL)translucent {
  21. self.tabBar.translucent = translucent;
  22. }
  23. - (void)setTabBarHideShadow:(BOOL)hideShadow {
  24. self.tabBar.clipsToBounds = hideShadow;
  25. }
  26. - (void)setTabBarVisible:(BOOL)visible animated:(BOOL)animated {
  27. const CGRect tabBarFrame = self.tabBar.frame;
  28. const CGRect tabBarVisibleFrame = CGRectMake(tabBarFrame.origin.x,
  29. self.view.frame.size.height - tabBarFrame.size.height,
  30. tabBarFrame.size.width,
  31. tabBarFrame.size.height);
  32. const CGRect tabBarHiddenFrame = CGRectMake(tabBarFrame.origin.x,
  33. self.view.frame.size.height,
  34. tabBarFrame.size.width,
  35. tabBarFrame.size.height);
  36. if (!animated) {
  37. self.tabBar.hidden = !visible;
  38. self.tabBar.frame = visible ? tabBarVisibleFrame : tabBarHiddenFrame;
  39. return;
  40. }
  41. static const CGFloat animationDuration = 0.15;
  42. if (visible) {
  43. self.tabBar.hidden = NO;
  44. [UIView animateWithDuration: animationDuration
  45. delay: 0
  46. options: UIViewAnimationOptionCurveEaseOut
  47. animations:^()
  48. {
  49. self.tabBar.frame = tabBarVisibleFrame;
  50. }
  51. completion:^(BOOL finished)
  52. {}];
  53. } else {
  54. [UIView animateWithDuration: animationDuration
  55. delay: 0
  56. options: UIViewAnimationOptionCurveEaseIn
  57. animations:^()
  58. {
  59. self.tabBar.frame = tabBarHiddenFrame;
  60. }
  61. completion:^(BOOL finished)
  62. {
  63. self.tabBar.hidden = YES;
  64. }];
  65. }
  66. }
  67. - (void)centerTabItems {
  68. [self.tabBar centerTabItems];
  69. }
  70. - (void)forEachTab:(void (^)(UIView *, UIViewController * tabViewController, int tabIndex))performOnTab {
  71. int tabIndex = 0;
  72. for (UIView * tab in self.tabBar.subviews) {
  73. if ([NSStringFromClass([tab class]) isEqualToString:@"UITabBarButton"]) {
  74. performOnTab(tab, [self childViewControllers][(NSUInteger) tabIndex], tabIndex);
  75. tabIndex++;
  76. }
  77. }
  78. }
  79. @end