简体   繁体   English

如何创建pinterest样式隐藏/取消隐藏导航/标签栏?

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

How do I create a hiding/unhiding nav bar like what pinterest and many other apps is doing? 如何创建一个隐藏/取消隐藏的导航栏,如pinterest和许多其他应用程序正在做什么? 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. 我知道基本的想法是使用UIScrollView委托并检测我是否向上或向下滚动并显示基于该导航栏的导航栏。 So should I also adjust the navcontroller view height if the nav bar is hidden? 如果导航栏被隐藏,我还应该调整导航控制器视图高度吗? How does this work? 这是如何运作的?

I have a sample project located on github that does exactly the pinterest/piictu style 'hide the UINavigationController / UITabBarController stuff' 我有一个位于github上的示例项目,它完全符合pinterest / piictu风格'隐藏UINavigationController / UITabBarController的东西'

https://github.com/tonymillion/ExpandingView https://github.com/tonymillion/ExpandingView

I've tried https://github.com/tonymillion/ExpandingView and ran into a bunch of issues. 我试过https://github.com/tonymillion/ExpandingView并遇到了很多问题。

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

}

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. 如果这种方法不起作用,我可能会创建自己的模拟导航控制器外观的控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM