2014-12-01 13 views
9

Mam następujące (uproszczone) hierarchii: UINavigationController -> UIViewController -> UITableViewController. Chciałbym ukryć pasek nawigacji po przewijaniu widoku tabeli przy użyciu hidesBarsOnSwipe. Teraz dzieje się tak, że pasek nawigacyjny ukrywa się za każdym razem, gdy przewijam w dół, ale nie pojawia się ponownie po przewinięciu w górę. Tak wygląda mój kod:hidesBarsOnSwipe dla 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

czy otrzymałeś rozwiązanie tego problemu? –

+0

Interesuje Cię, czy to też zostało rozwiązane. –

Odpowiedz

0

To powinno zadziałać.

Najpierw dodaj UIScrollViewDelegate do pliku your.h lub .m.

Następnie dodaj następujące metody delegatów.

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

}