react-native-navigation的迁移库

UINavigationController+RNNOptions.m 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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)setNavigationBarLargeTitleVisible:(BOOL)visible {
  28. if (@available(iOS 11.0, *)) {
  29. if (visible){
  30. self.navigationBar.prefersLargeTitles = YES;
  31. } else {
  32. self.navigationBar.prefersLargeTitles = NO;
  33. }
  34. }
  35. }
  36. - (void)setNavigationBarBlur:(BOOL)blur {
  37. if (blur && ![self.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
  38. [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  39. self.navigationBar.shadowImage = [UIImage new];
  40. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  41. CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
  42. blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, self.navigationBar.frame.size.width, self.navigationBar.frame.size.height + statusBarFrame.size.height);
  43. blur.userInteractionEnabled = NO;
  44. blur.tag = BLUR_TOPBAR_TAG;
  45. [self.navigationBar insertSubview:blur atIndex:0];
  46. [self.navigationBar sendSubviewToBack:blur];
  47. } else {
  48. UIView *blur = [self.navigationBar viewWithTag:BLUR_TOPBAR_TAG];
  49. if (blur) {
  50. [self.navigationBar setBackgroundImage: nil forBarMetrics:UIBarMetricsDefault];
  51. self.navigationBar.shadowImage = nil;
  52. [blur removeFromSuperview];
  53. }
  54. }
  55. }
  56. - (void)setBackButtonColor:(UIColor *)color {
  57. self.navigationBar.tintColor = color;
  58. }
  59. - (void)setNavigationBarClipsToBounds:(BOOL)clipsToBounds {
  60. self.navigationBar.clipsToBounds = clipsToBounds;
  61. }
  62. - (CGFloat)getTopBarHeight {
  63. return self.navigationBar.frame.size.height;
  64. }
  65. @end