[英]hidesBarsOnSwipe for childView
我有以下(简化)层次结构: UINavigationController -> UIViewController -> UITableViewController
。 当我使用hidesBarsOnSwipe
滚动我的tableview时,我想隐藏导航栏。 现在发生的是每当我向下滚动时导航栏都会隐藏,但是当我向上滚动时它不会再出现。 这就是我的代码:
// Create a navigation controller and set as root view controller
// Enable hidesBarsOnSwipe
UINavigationController *navigationC = [UINavigationController new];
self.window.rootViewController = navigationC;
navigationC.hidesBarsOnSwipe = YES;
// Create a view controller to act as parent for the table view
UIViewController *parentVC = [UIViewController new];
[navigationC pushViewController:parentVC animated:NO];
// Create the table view controller
UITableViewController *tableVC = [UITableViewController new];
tableVC.tableView.dataSource = self;
// Add the table view as a subview to the parent view controller
[parentVC addChildViewController:tableVC];
[parentVC.view addSubview:tableVC.tableView];
[tableVC didMoveToParentViewController:parentVC];
这应该工作。
首先在your.h或.m文件中添加UIScrollViewDelegate。
然后添加以下委托方法。
#pragma mark - UIScrollViewDelegate Methods
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastContentOffsetY = scrollView.contentOffset.y;
}
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
bool shouldHide = (scrollView.contentOffset.y > self.lastOffsetY);
[[self navigationController] setNavigationBarHidden:shouldHide animated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.