react-native-navigation的迁移库

UITabBarController+RNNOptions.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. @end