Rectangle 27 0

ios UIScrollView dynamic status bar?


func scrollViewDidScroll(scrollView: UIScrollView){
    let xOffset = scrollView.contentOffset.x;


    if(xOffset > scrollView.contentSize.width/4)
    {
        if hidden == true {
            print("\nShow status bar\n")

            hidden = false
            UIView.animateWithDuration(0.3, animations: {
                self.setNeedsStatusBarAppearanceUpdate()
            })
        }
    } else
    {
       print("\nHide Status Bar\n")

        hidden = true
        UIView.animateWithDuration(0.2, animations: {
            self.setNeedsStatusBarAppearanceUpdate()
        })
    }
}

override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
    if hidden == false {
        return UIStatusBarAnimation.Fade
    } else {
        return UIStatusBarAnimation.Slide
    }
}

override func prefersStatusBarHidden() -> Bool {
    print("\nstatus Bar Changed to hidden = \(hidden)\n")
    return hidden
}

It fades the status bar in once you've at least scrolled half way, and slides the status bar back up once you've gone back half way again.

Solution I found (More of a workaround) declare a boolean called hidden. Then I overrode these methods:

Note