react-native-navigation的迁移库

UITabBarController+RNNOptions.m 2.5KB

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