Scenario
我有一个应用程序,它使用标签栏控制器(屏幕底部)和导航控制器(屏幕顶部)UI 设计。在一个视图控制器上,我有一个 UITableView,其中包含用户将“向上滑动”以滚动表格以查看内容的内容。
Need
很像雅虎!和 Instagram 应用程序,我希望能够在感知到用户在 tableView 上向上滑动时让顶部导航栏和底部选项卡栏“收缩”并“消失”。当然,当用户再次向下滑动时,我希望它们都重新出现。
Question
有谁知道如何做到这一点?
To hide UITabbar
of UITabbarController
其中包含UINavigationController
with UITableViewController
在堆栈中应该使用hidesBarsOnSwipe
属性并添加自定义选择器barHideOnSwipeGestureRecognizer
:
@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];
}
这样就可以同时隐藏选项卡栏和状态栏。还可以添加一些动画效果来隐藏/显示这些栏。
之前删除选择器非常重要self
已被解除分配。否则,下次使用时肯定会崩溃barHideOnSwipeGestureRecognizer
with self.navigationController
.
请注意,此方法仅适用于 iOS8+。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)