iOS 隐藏导航栏时切换页面出现黑条的解决办法

解决方法如下:

实现UINavigationControllerDelegate的- navigationController:willShowViewController:animated: 方法

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationController.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UINavigationControllerDelegate -
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    //判断当前viewController 是否是需要隐藏导航栏,如果是需要隐藏的VC isViewController将为YES 反之 NO 将会显示出导航栏
    //其中viewController为navigationController: willShowViewController: animated: 方法里的参数viewController
    //[ViewController class]中的ViewController为具体需要隐藏导航栏的类名
    BOOL isViewController = [viewController isKindOfClass:[ViewController class]];
    [navigationController setNavigationBarHidden:isViewController animated:true];

}

@end

博主大大

假如生活欺骗了你,不要悲伤,不要难过,反正明天也一样......

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

猜你喜欢