UITableView:缩小标签栏和导航栏上滑动

脚本

我有一个使用导航控制器(屏幕顶部)UIdevise的选项卡栏控制器(屏幕底部)的应用程序。 在一个视图控制器我有一个UITableView的内容,用户将“向上滑动”滚动查看内容的表。

需要

就像Yahoo! 和Instagram的应用程序,我希望能够有顶部的导航栏和底部的标签栏“收缩”和“消失”,当它感觉到用户刷在桌面上。 当然,当用户再次下滑时,我希望他们都能重新出现。

有谁知道如何做到这一点?

要在UITableViewController中隐藏包含UINavigationController UITabbarUITabbarController ,应使用hidesBarsOnSwipe属性并为barHideOnSwipeGestureRecognizer添加自定义select器:

 @implementation SomeTableViewController - (void)willMoveToParentViewController:(UIViewController *)parent { if (parent) { self.navigationController.hidesBarsOnSwipe = YES; [self.navigationController.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)]; } else { self.navigationController.hidesBarsOnSwipe = NO; [self.navigationController.barHideOnSwipeGestureRecognizer removeTarget:self action:@selector(swipe:)]; } } - (void)swipe:(UIPanGestureRecognizer *)recognizer { UINavigationBar *bar = self.navigationController.navigationBar; BOOL isHidden = (bar.frame.origin.y < 0); [self.tabBarController.tabBar setHidden:isHidden]; [[UIApplication sharedApplication] setStatusBarHidden:isHidden withAnimation:UIStatusBarAnimationSlide]; } 

这样可以隐藏tabbar和statusBar。 也可以添加一些animation效果隐藏/揭示这些酒吧。

在释放self之前,删除select器非常重要。 否则,你将得到保证崩溃的下一个使用barHideOnSwipeGestureRecognizerself.navigationController

注意这种方法只适用于iOS8 +。