react-native-navigation的迁移库

UINavigationController+RNNOptions.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #import "UINavigationController+RNNOptions.h"
  2. #import "RNNFontAttributesCreator.h"
  3. const NSInteger BLUR_TOPBAR_TAG = 78264802;
  4. @implementation UINavigationController (RNNOptions)
  5. - (void)setInteractivePopGestureEnabled:(BOOL)enabled {
  6. self.interactivePopGestureRecognizer.enabled = enabled;
  7. }
  8. - (void)setRootBackgroundImage:(UIImage *)backgroundImage {
  9. UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;
  10. if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
  11. backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
  12. [self.view insertSubview:backgroundImageView atIndex:0];
  13. }
  14. backgroundImageView.layer.masksToBounds = YES;
  15. backgroundImageView.image = backgroundImage;
  16. [backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
  17. }
  18. - (void)setNavigationBarTestId:(NSString *)testID {
  19. self.navigationBar.accessibilityIdentifier = testID;
  20. }
  21. - (void)setNavigationBarVisible:(BOOL)visible animated:(BOOL)animated {
  22. [self setNavigationBarHidden:!visible animated:animated];
  23. }
  24. - (void)hideBarsOnScroll:(BOOL)hideOnScroll {
  25. self.hidesBarsOnSwipe = hideOnScroll;
  26. }
  27. - (void)setBarStyle:(UIBarStyle)barStyle {
  28. self.navigationBar.barStyle = barStyle;
  29. }
  30. - (void)setNavigationBarLargeTitleVisible:(BOOL)visible {
  31. if (@available(iOS 11.0, *)) {
  32. if (visible){
  33. self.navigationBar.prefersLargeTitles = YES;
  34. } else {
  35. self.navigationBar.prefersLargeTitles = NO;
  36. }
  37. }
  38. }
  39. - (void)setNavigationBarBlur:(BOOL)blur {
  40. if (blur && ![self.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
  41. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  42. self.navigationBar.shadowImage = [UIImage new];
  43. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  44. CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
  45. blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, self.navigationBar.frame.size.width, self.navigationBar.frame.size.height + statusBarFrame.size.height);
  46. blur.userInteractionEnabled = NO;
  47. blur.tag = BLUR_TOPBAR_TAG;
  48. [self.navigationBar insertSubview:blur atIndex:0];
  49. [self.navigationBar sendSubviewToBack:blur];
  50. } else {
  51. UIView *blur = [self.navigationBar viewWithTag:BLUR_TOPBAR_TAG];
  52. if (blur) {
  53. [self.navigationBar setBackgroundImage: nil forBarMetrics:UIBarMetricsDefault];
  54. self.navigationBar.shadowImage = nil;
  55. [blur removeFromSuperview];
  56. }
  57. }
  58. }
  59. - (void)setBackButtonColor:(UIColor *)color {
  60. self.navigationBar.tintColor = color;
  61. }
  62. - (void)setNavigationBarClipsToBounds:(BOOL)clipsToBounds {
  63. self.navigationBar.clipsToBounds = clipsToBounds;
  64. }
  65. - (CGFloat)getTopBarHeight {
  66. return self.navigationBar.frame.size.height;
  67. }
  68. @end