iOS

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


avatar
博主大大 2017-02-06 3.31k

解决方法如下:

实现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

相关阅读