iOS如何导航栏无缝圆滑的隐藏Navigationbar-成都快上网建站

iOS如何导航栏无缝圆滑的隐藏Navigationbar

这篇文章将为大家详细讲解有关iOS如何导航栏无缝圆滑的隐藏Navigationbar,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

十多年的陕州网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整陕州建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“陕州网站设计”,“陕州网站推广”以来,每个客户项目都认真落实执行。

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 ()

代理方法

- (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 ()

手势代理方法

- (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如何导航栏无缝圆滑的隐藏Navigationbar

关于“iOS如何导航栏无缝圆滑的隐藏Navigationbar”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


本文题目:iOS如何导航栏无缝圆滑的隐藏Navigationbar
URL标题:http://kswjz.com/article/jepjig.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流