I am currently using Scroll View with different pages. I am trying to hide the Status Bar on one specific page. There is a really annoying lag , and the screen freezes every time the Status Bar is about to appear / disappear again.
This is my approach:
First of all, I defined two variables
private var currentPage = 0 private var isStatusBarPreferablyHidden = true
Then I used two functions from the scroll delegate to call setNeedsStatusBarAppearanceUpdate when the user moved to the first page
func scrollViewDidScroll(_ scrollView: UIScrollView) { let currentScrollPosition : CGFloat = self.navigation.contentOffset.x / self.navigation.frame.size.width currentPage = lroundf(Float(currentScrollPosition)) } func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) { if currentPage == 0 { isStatusBarPreferablyHidden = true } else { isStatusBarPreferablyHidden = false } self.setNeedsStatusBarAppearanceUpdate() }
Finally, I redefined the status bar functions to update the appearance of the status bar.
override var prefersStatusBarHidden: Bool { return isStatusBarPreferablyHidden } override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { return UIStatusBarAnimation.none }
source share