iOS导航栏的一些小技巧

一 隐藏系统导航栏

  • 1 继承UINavigationControllerDelegate
  • 2 在viewWillAppear中设置代理
(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
}
  • 3 判断当前要显示的viewController是不是自己,来设置导航栏的隐藏与否
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL target = [viewController isKindOfClass:[self class]];
    [self.navigationController target animated:YES];
}

二 添加系统右滑返回手势

  • 1 继承UIGestureRecognizerDelegate
  • 2 在当前要实现系统右滑返回的控制器中加入 self.navigationController.interactivePopGestureRecognizer.delegate = self 即可
 self.navigationController.interactivePopGestureRecognizer.delegate = self;

三 单独禁止某个页面系统的滑动返回功能

id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
 UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
 [self.view addGestureRecognizer:pan];

你可能感兴趣的:(iOS导航栏的一些小技巧)