2015-10-07 77 views
2

我想在iOS8中使用命令来启用隐藏导航栏滚动时的行为。hidesBarsOnSwipe不显示导航栏时,滚动到顶部缓慢

下面是代码

-(void)viewDidAppear:(BOOL)animated 
{ 
    self.navigationController.hidesBarsOnSwipe = YES; 
} 

和滚动起来快的时候,是没有问题的,因为导航栏会自动拖累可见。但即使我慢慢滚动到顶部。导航栏不显示。

我试图通过使用scrollView委托来纠正这种行为。但那也行不通。因为动画看起来不太好。

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

if(floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_8_0) 
{ 
    float scrollOffset = scrollView.contentOffset.y; 

    if (scrollOffset < 10) 
    { 
     self.navigationController.navigationBarHidden = NO; 
    } 
} 

} 

请帮忙。我想尽可能简单地做到这一点。在此先感谢

+0

我有同样的问题。你有没有找到解决方案? https://github.com/andreamazz/AMScrollingNavbar,你可以试试这个。 – App07

+0

我找到了解决方案。但还有另一个问题。设置hidesBarsOnSwipe = YES。有时会让应用崩溃。我找不到解决办法。所以我决定暂时禁用此功能。 –

回答

2

要显示时,它已经达到了顶部,使用以下

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    if indexPath.row == 0 { 
    self.navigationController?.hidesBarsOnSwipe = false 
    self.navigationController?.setNavigationBarHidden(false, animated: true) 
    } 
    else { 
    self.navigationController?.hidesBarsOnSwipe = true 
} 
+1

为了这样的目的,最好使用tableView willDisplayRowAtIndexPath方法 – arrteme

0

我曾与在顶部右侧约束一个UIScrollView,但还是它的行为很奇怪。

我解决了这种方式:

-(void)scrollViewDidScroll: (UIScrollView*)scrollView 
{ 
    float scrollViewHeight = scrollView.frame.size.height; 
    float scrollContentSizeHeight = scrollView.contentSize.height; 
    float scrollOffset = scrollView.contentOffset.y; 

    if (scrollOffset < 0) 
    { 
     self.navigationController.hidesBarsOnSwipe = NO; 
     [self.navigationController setNavigationBarHidden:NO animated: YES]; 
    } 
    else 
    { 
     self.navigationController.hidesBarsOnSwipe = YES; 
    } 
}