Xcode / iOS的:如何隐藏导航和工具栏向下滚动?

我想在iPhone上向下滚动两栏。 当我向上滚动时,他们应该再次出现..我该如何处理?

接受的答案不适用于我,因为scrollViewWillBeginScroll:不是委托方法。

相反,我呢

 -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldHide" object:self]; } -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if(!decelerate) [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide" object:self]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide" object:self]; } 

应用程序对象中的任何位置都可以侦听此通知

 - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldHide" object:nil queue:nil usingBlock:^(NSNotification *note) { //hide tab bar with animation; }]; [[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldUnhide" object:nil queue:nil usingBlock:^(NSNotification *note) { //Unhide tab bar with animation; }]; } 

这段代码将隐藏任何滚动条。 如果你只想下去,那么在接受的答案中的相同locationOffset技巧应该工作。

 - (void)scrollViewWillBeginScroll :(UIScrollView *)scrollView { if (scrollView.contentOffset.y < lastOffset.y) { [toolBar setHidden:YES]; [[[self navigationController] navigationBar] setHidden:YES]; } else{ // unhide } } - (void)scrollViewDidScroll :(UIScrollView *)scrollView { /// blah blah lastOffset = scrollView.contentOffset; } 

注意lastOffset是一个CGPoint ,它在你的头文件中: @Interface

这是我在Swift中的解决scheme。 它的作品非常漂亮

 func scrollViewDidScroll(scrollView: UIScrollView) { let navController: UINavigationController = self.navigationController! if self.collectionView.panGestureRecognizer.translationInView(self.view).y <= 0.0 { defaultCenter.postNotificationName("stuffShouldHide", object: self) } else { defaultCenter.postNotificationName("stuffShouldUnhide", object: self) } } 

你可能会检查这个,从iOS8可用,我认为这是你正在寻找的相反…但值得检查,因为它是标准的东西,这是如何工作的Safari。

迅速

var hidesBarsOnSwipe:Bool

Objective-C的

@属性(非primefaces,读写,分配)BOOL hidesBarsOnSwipe讨论

当此属性设置为YES时,向上滑动可隐藏导航栏和工具栏。 向下滑动再次显示两个酒吧。 如果工具栏没有任何项目,即使在滑动之后,它仍然可见。 该属性的默认值是NO。