react-native-navigation的迁移库

UINavigationController+RNNOptions.m 2.3KB

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