Cbas
Cbas

Reputation: 6213

status bar expanding scrollview and pushing content off screen

I have a vertical, paging enabled scroll view with two pages and I want to show the status bar on the top page, but not on the bottom page.

I tried using the UIScrollViewDelegate methods to show/hide the status bar whenever the view has finished scrolling:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  // top page
  if (scrollView.contentOffset.y == 0){
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    [self.delegate messagesActive:self];
  } 
  // bottom page
  else if (scrollView.contentOffset.y == self.view.frame.size.height){
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
  }
}

But every time I scroll from the bottom page to the top page, the status bar creates its own space above my page view, and pushes the view down off the screen. This happens with or without the fade animation.

enter image description here

The next screen touch somehow forces the views to correct themselves with a sliding animation:

enter image description here

How can I make the status bar overlay my view right away instead of expanding space above it?

Upvotes: 1

Views: 703

Answers (1)

Cbas
Cbas

Reputation: 6213

// ... in viewDidLoad
self.automaticallyAdjustsScrollViewInsets = NO

Also, starting in iOS 9, UIApplication setStatusBarHidden is deprecated and should not be used. This technique is equally applicable for dynamic and animated status bars: setStatusBarHidden(_:withAnimation:) deprecated in iOS 9

Upvotes: 1

Related Questions