本文介绍了如何隐藏导航栏而不会失去滑回功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UITableView,它有一个导航栏(来自UINavigationViewController),它可以通过用手指向后滑回来。
我试图隐藏导航栏但保持向后滑动的能力,代码:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
这成功隐藏了导航栏,但我无法再滑回最后一个屏幕。
有没有办法隐藏导航栏但保留回滑功能?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//隐藏导航栏
[[self navigationController] setNavigationBarHidden:YES animated:YES];
//启用回滚
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
返回YES;
}
在.h文件中,符合UIGestureRecognizerDelegate
I have a UITableView and it has a nav bar(got from UINavigationViewController), it's able to go back by sliding back using a finger.
I tried to hide the nav bar but keep the slide-back ability, code:
- (void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
This successfully hid the nav bar, however, I can no longer slide back to the last screen either.
Is there any way to hide the nav bar but keep the slide-back ability?
解决方案
Found the solution:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// hide nav bar
[[self navigationController] setNavigationBarHidden:YES animated:YES];
// enable slide-back
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
And in .h file, conform to UIGestureRecognizerDelegate
这篇关于如何隐藏导航栏而不会失去滑回功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 01:31