// // BaseNavigationController.m // YUMI // // Created by zu on 2021/9/7. // #import "BaseNavigationController.h" ///Tool #import "DJDKMIMOMColor.h" @interface BaseNavigationController () @end @implementation BaseNavigationController -(void)dealloc{ [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = self; } [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(switchLanguage) name:@"kNavViewUpdateWhenLanguageUpdate" object:nil]; [self themeConfig]; if(isMSRTL()){ self.navigationBar.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;; self.view.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; }else{ self.navigationBar.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;; self.view.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; } } -(void)switchLanguage{ if(isMSRTL()){ self.navigationBar.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; self.view.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; }else{ self.navigationBar.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; self.view.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; } } - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { if(self.topViewController == viewController) return; [super pushViewController:viewController animated:animated]; } - (void)backClick{ [self popViewControllerAnimated:YES]; } - (void)themeConfig { self.navigationBar.shadowImage = [[UIImage alloc] init]; self.navigationBar.barTintColor = [DJDKMIMOMColor appBackgroundColor]; self.navigationBar.tintColor = [UIColor whiteColor]; self.navigationBar.translucent = NO; self.view.backgroundColor = [DJDKMIMOMColor appBackgroundColor]; [self.navigationBar setTitleTextAttributes:@{ NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightMedium], NSForegroundColorAttributeName:[DJDKMIMOMColor mainTextColor] }]; /// scrollEdgeAppearance 属性iOS15 强制适用于 所有导航器 如果为nil 则使用 standardAppearance属性中的设置,并修改为使用透明背景 @fengshuo if (@available(iOS 15.0, *)) { UINavigationBarAppearance *appearance = [UINavigationBarAppearance new]; appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightMedium], NSForegroundColorAttributeName:[DJDKMIMOMColor mainTextColor]}; appearance.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor]; self.navigationBar.standardAppearance = appearance; self.navigationBar.scrollEdgeAppearance = appearance; } } #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; } @end