[英]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.