2014-12-01 35 views
9

我有以下(簡化)層次結構:UINavigationController -> UIViewController -> UITableViewController。當我使用hidesBarsOnSwipe滾動我的tableview時,我想隱藏導航欄。現在發生的事情是,當我向下滾動時,導航欄隱藏,但當我向上滾動時,它不會再出現。這是我的代碼看起來像:hidesBarsOnSwipe for childView

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

您是否得到了解決方案? – 2015-10-12 14:16:41

+0

有興趣知道這是否也解決了。 – 2016-03-02 15:59:10

回答

0

這應該工作。

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

} 
相關問題