将navigationBar背景图像设置为[UIImage new]后恢复 [英] Restore navigationBar background image after setting it to [UIImage new]

查看:471
本文介绍了将navigationBar背景图像设置为[UIImage new]后恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个完全透明的mapView导航栏,所以我这样做了:

I needed a completely transparent navigation bar for the mapView so I did this:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

返回所需的效果,如下所示:

That returns the desired effect, as seen here:

现在当我去其他任何地方时我遇到问题,因为我的navigationBar仍然是透明的:

Now I have a problem when I go to any other because my navigationBar remains transparent:

如何恢复navigationBar的backgroundImage和shadowImage的默认设置?

How do I restore default settings of the navigationBar's backgroundImage and shadowImage?

推荐答案

在地图视图上 viewWillDisappear 上为导航图像设置 nil

Set nil for image of navigation Controller on viewWillDisappear on map view

在mapview中设置这两种方法

Set this two method in your mapview

MapView .m

-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}

-(void)viewWillDisappear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

这篇关于将navigationBar背景图像设置为[UIImage new]后恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆