Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hidesBarsOnSwipe does not show navigationBar when scrolling up to the top slowly

I am trying to use a command in iOS8 to enable behaviour to hide navigation bar when scrolling.

Here is the code

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

And when scrolling up quick, there is no problem because the navigation bar will be dragged down and visible automatically. But in the even if I scroll up to the top slowly. The navigation bar does not show.

I tried to correct this behavior by using scrollView delegate. But that does not work well also. Because the animation does not look nice.

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

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

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

}

Please help. I would like to do this as simple as possible. Thanks in advance

like image 712
Kong Hantrakool Avatar asked Oct 07 '15 12:10

Kong Hantrakool


3 Answers

To show when it has reached the top, use the following

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
}
like image 155
Mahesh Lad Avatar answered Nov 09 '22 23:11

Mahesh Lad


I just faced same problem.

When i used hidesBarsOnSwipe property of UINavigationController. I can not show it again on scroll/swipe. In my case i was using UIScrollView and scrollview's top was Aling to SafeArea.Top

I just changed scrollview's Top to SuperView.Top, and its works.

Thanks.

like image 42
Jatin Chauhan Avatar answered Nov 10 '22 01:11

Jatin Chauhan


I had a UIScrollView with the right constraints on the top, but still its behavior was weird.

I solved in this way:

-(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;
    }
}
like image 33
ivoroto Avatar answered Nov 10 '22 01:11

ivoroto