react-native-navigation的迁移库

UINavigationController+RNNOptions.m 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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)setBackButtonColor:(UIColor *)color {
  48. self.navigationBar.tintColor = color;
  49. }
  50. - (void)setNavigationBarClipsToBounds:(BOOL)clipsToBounds {
  51. self.navigationBar.clipsToBounds = clipsToBounds;
  52. }
  53. - (CGFloat)getTopBarHeight {
  54. return self.navigationBar.frame.size.height;
  55. }
  56. @end