欢迎来到代码驿站!

iOS代码

当前位置:首页 > 移动开发 > iOS代码

iOS 导航栏无缝圆滑的隐藏 Navigationbar实例代码

时间:2023-01-02 09:22:34|栏目:iOS代码|点击:

1.ViewController

.m

- (void)viewDidLoad {
 [super viewDidLoad];
 self.title = @"隐藏导航栏";
 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
 button.backgroundColor = [UIColor lightGrayColor];
 button.frame = CGRectMake(10, 100, 60, 30);
 [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
 [self.view addSubview:button];
 self.navigationController.delegate = self;
}
- (void)buttonClick{
 ///跳转到KKViewController
 [self performSegueWithIdentifier:@"pusht" sender:nil];
}

头部代理

@interface ViewController ()<UINavigationControllerDelegate>

代理方法

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
 [self.navigationController setNavigationBarHidden: [self hiddenBarVc: viewController] animated: animated];
}
- (BOOL)hiddenBarVc:(UIViewController *)viewController {
 BOOL needHideNaivgaionBar = NO;
 if ([viewController isKindOfClass: [KKViewController class]]) {
 needHideNaivgaionBar = YES;
 }
 return needHideNaivgaionBar;
}

2.KKViewController(目标ViewController)

新建一个KKViewController

.h

@property (nonatomic,strong) id popDelegate;

.m

- (void)viewDidLoad {
 [super viewDidLoad];
 self.title = @"第二个页面";
 [self popSet];
}
- (void)popSet{
 _popDelegate = self.navigationController.interactivePopGestureRecognizer.delegate;
 SEL action = NSSelectorFromString(@"handleNavigationTransition:");
 UIPanGestureRecognizer *popPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.popDelegate action:action];
 popPanGesture.maximumNumberOfTouches = 1;
 popPanGesture.delegate = self;
 [self.view addGestureRecognizer: popPanGesture];
}

头部代理

@interface KKViewController ()<UIGestureRecognizerDelegate>

手势代理方法

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
 ///【下面两个方法写一个】
 ///全屏拖动
 CGPoint tragPoint = [gestureRecognizer translationInView:gestureRecognizer.view];
 if (tragPoint.x <= 0){
  return NO;
 }
 else{
  if (self.navigationController.viewControllers.count <= 1){
   return NO;
  }
  else{
   return YES;
  }
 }
// ///局部允许拖动
// CGPoint tragPoint = [gestureRecognizer locationInView:gestureRecognizer.view];
// NSLog(@"x=%f;y=%f",tragPoint.x,tragPoint.y);
// if (tragPoint.x > 60){///拖动的范围
//  return NO;
// }
// else{
//  if (self.navigationController.viewControllers.count <= 1) {
//   return NO;
//  }
//  else{
//   return YES;
//  }
// }
}

效果图

总结

上一篇:iOS中UIScrollerView的用法及基于AotoLayout的控件悬停

栏    目:iOS代码

下一篇:没有了

本文标题:iOS 导航栏无缝圆滑的隐藏 Navigationbar实例代码

本文地址:http://www.codeinn.net/misctech/222790.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有