我正在尝试在网络视图上实现点按手势,以隐藏/显示导航栏,标签栏和状态栏。我隐藏/显示导航栏工作正常,我可以隐藏状态栏但不能让它显示备份。标签栏项目被隐藏但条形图仍然存在。任何人都可以帮忙吗?
- (void)toggleBars:(UITapGestureRecognizer *)gesture
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
BOOL statusBarHidden = YES;
BOOL barsHidden = self.navigationController.navigationBar.hidden;
[self.navigationController setNavigationBarHidden:!barsHidden animated:YES];
BOOL tabBarHidden = self.tabBarController.tabBar.hidden;
[self.tabBarController.tabBar setHidden:!tabBarHidden];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showMenu)];
self.navigationItem.rightBarButtonItem = systemAction;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(toggleBars:)];
[webView addGestureRecognizer:singleTap];
singleTap.delegate = self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
编辑:看起来标签栏正在隐藏,但我的webview只是没有填充空白区域。当隐藏标签栏时,如何填充空间?
答案 0 :(得分:4)
首先,您的状态栏永远不会取消隐藏,因为您永远不会告诉它。编写代码时,只需告诉状态栏每次执行时都要隐藏。
[[UIApplication sharedApplication] setStatusBarHidden:![[UIApplication sharedApplication] isStatusBarHidden] withAnimation:UIStatusBarAnimationSlide];
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBar.hidden animated:YES];
此外,我不确定标签栏未正确隐藏的详细信息,但我确实找到了以下类别,声称可以使用选项动画隐藏标签栏。
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden
答案 1 :(得分:1)
我通过将其添加到我的toggleBars方法来获取隐藏/显示的状态栏,但我仍然没有弄清楚为什么标签栏项会隐藏但不会隐藏标签栏本身。
if (([UIApplication sharedApplication].statusBarHidden = YES))
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}