【问题标题】:hidesBarsOnSwipe for childViewhidesBarsOnSwipe for childView
【发布时间】:2015-01-29 16:59:20
【问题描述】:

我有以下(简化的)层次结构:UINavigationController -> UIViewController -> UITableViewController。当我使用hidesBarsOnSwipe 滚动我的表格视图时,我想隐藏导航栏。现在发生的情况是,每当我向下滚动时导航栏就会隐藏,但当我向上滚动时它不会重新出现。这是我的代码的样子:

// 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];

【问题讨论】:

  • 你找到解决方案了吗?
  • 有兴趣知道这是否也解决了。
  • 你解决了吗?

标签: ios uitableview ios8 uinavigationbar


【解决方案1】:

这应该可行。

首先在 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];

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-28
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    相关资源
    最近更新 更多