iOS 导航栏返回把样式带回前面怎么办

//设置当前页面导航栏
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    // 让导航栏背景透明
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

    if (@available(iOS 13.0, *)) {
            UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
            [appearance configureWithOpaqueBackground];
            // 改变导航栏的颜色
            appearance.backgroundColor = [UIColor clearColor];
            // 改变导航栏的标题颜色,这里改没什么用的,要去继承的父类那里去改就是 YHNavigationController.m那里
            appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],
                                              NSForegroundColorAttributeName:[UIColor whiteColor]};
            //导航栏包含状态栏 阴影线颜色背景色设置
            appearance.shadowColor = [UIColor clearColor];
            self.navigationController.navigationBar.standardAppearance = appearance;
            self.navigationController.navigationBar.scrollEdgeAppearance = self.navigationController.navigationBar.standardAppearance;
    }
//    self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];//右边的按钮颜色
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    self.navigationItem.backBarButtonItem.tintColor = [UIColor blackColor];
}
//返回时恢复到前面的导航栏
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    // 导航栏恢复不透明显示
    UIColor *topColor = [EBSkinLib shareInstance].globalColor_3;
    
    UIColor *bottomColor = [EBSkinLib shareInstance].globalColor;
    
    UIImage *bgImg = [UIImage gradientColorImageFromColors:@[topColor, bottomColor] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(self.view.frame.size.width, navBarHeight)];
    
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setBackgroundImage:bgImg forBarMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.barTintColor = barTineColor;
    
}
原文地址:https://www.cnblogs.com/gaozhang12345/p/15787488.html