Rea*_*son 12 uinavigationbar uitableview ios ios8
我有以下(简化)层次结构:UINavigationController -> UIViewController -> UITableViewController.当我使用滚动我的tableview时,我想隐藏导航栏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];
Run Code Online (Sandbox Code Playgroud)
小智 -1
这应该有效。
首先在 .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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
919 次 |
| 最近记录: |