Reputation: 6213
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.
The next screen touch somehow forces the views to correct themselves with a sliding animation:
How can I make the status bar overlay my view right away instead of expanding space above it?
Upvotes: 1
Views: 703
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