2014-01-14 90 views
4

我有一個應用程序,我想隱藏我的導航欄,當向上滾動到UITableView。我做這樣的在iPhone中隱藏像Instagram或Facebook的導航欄?

- (void)scrollViewDidScroll:(UIScrollView *)sender { 

    //Initializing the views and the new frame sizes. 
    UINavigationBar *navbar = self.navigationController.navigationBar; 
    UIView *tableView = self.view; 

    CGRect navBarFrame = self.navigationController.navigationBar.frame; 
    CGRect tableFrame = self.view.frame; 

    //changing the origin.y based on the current scroll view. 
    //Adding +20 for the Status Bar since the offset is tied into that. 
    navBarFrame.origin.y = MIN(0, (sender.contentOffset.y * -1)) +20; 
    navbar.frame = navBarFrame; 

    tableFrame.origin.y = MIN(0,MAX(-44,(sender.contentOffset.y * -1))); 
    tableView.frame = tableFrame;  
} 

但問題是,它是完全向上移動在iOS的7我需要它的狀態欄下停止並顯示有狀態欄。

+2

看看這個庫https://github.com/andreamazz/AMScrollingNavbar –

+1

您是否嘗試過任何這些解決方案? http://stackoverflow.com/questions/19819165/imitate-ios-7-facebook-hide-show-expanding-contracting-navigation-bar –

+0

我嘗試了所有這些,在第一個滾動開始內容時偏移量正在變化,不會回到0 – hacker

回答