how to create pinterest style hiding/unhiding nav/tab bar?

梦想与她 提交于 2019-12-20 09:39:57

问题


How do I create a hiding/unhiding nav bar like what pinterest and many other apps is doing? I know the basic idea is to use the UIScrollView delegate and detect whether I am scrolling up or down and show the nav bar based on that. So should I also adjust the navcontroller view height if the nav bar is hidden? How does this work?


回答1:


I have a sample project located on github that does exactly the pinterest/piictu style 'hide the UINavigationController / UITabBarController stuff'

https://github.com/tonymillion/ExpandingView




回答2:


I've tried https://github.com/tonymillion/ExpandingView and ran into a bunch of issues.

I ended up rolling my own navigation controller to get all the animations synced and used this scrollview code to figure out if I should expand or contract. iOS >=5.0

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    MyCustomNavController* navController = (MyCustomNavController*)self.parentViewController;
    if( [scrollView.panGestureRecognizer translationInView:self.view].y  < 0.0f ) {
        [navController setExpanded:YES animated:YES];
    } else if ([scrollView.panGestureRecognizer translationInView:self.view].y  > 0.0f  ) {
        [navController setExpanded:NO animated:YES];
    }

}



回答3:


I would probably try to create my own root controller with scrollbar as main view and put navigation controller's view into it. You can't use scrollbar inside navbar view then but I believe you don't need it in this very case.

If this approach doesn't work I would probably create my own controller that mimic navigation controller appearance.



来源:https://stackoverflow.com/questions/9530493/how-to-create-pinterest-style-hiding-unhiding-nav-tab-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!