I have a table view controller. When user scroll the table up, I want to hide iphone status bar(the top one which includes battery, WIFI etc.) gradually. I know how to hide the status bar by implementing prefersStatusBarHidden() method. But it doesn't hide it with the table scrolling up. So I want it to be kind of part of the table. It should be able to move with the table moving.
-
1Possible duplicate of [Proper way to hide status bar on iOS, with animation and resizing root view](http://stackoverflow.com/questions/13624695/proper-way-to-hide-status-bar-on-ios-with-animation-and-resizing-root-view) – mohonish Mar 09 '16 at 05:54
3 Answers
initially you get scroll direction of UItableview , then set as BOOL value based on direction
func scrollViewDidScroll(scrollView: UIScrollView) {
if(scrollView.panGestureRecognizer.translationInView(scrollView.superview).y > 0)
{
print("up")
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: .Fade) //.Slide
}
else
{
print("down")
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: .Fade) //.Slide
}
}
UIApplication.sharedApplication().setStatusBarHidden is deprecated in iOS9
Choice-2
crete one global Value for get the current position
var hide:Bool = false
func scrollViewDidScroll(scrollView: UIScrollView) {
if(scrollView.panGestureRecognizer.translationInView(scrollView.superview).y > 0)
{
print("up")
hide = true
}
else
{
print("down")
hide = false
}
UIView.animateWithDuration(0.5) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
}
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
return UIStatusBarAnimation.Slide
}
override func prefersStatusBarHidden() -> Bool {
return hide
}

- 82,064
- 23
- 174
- 143
There is no way to move the status bar; it is either visible or hidden. However, you can get around this by replacing the status when the UITableView
is about to be scrolled with a UIView
containing a screenshot that includes the status bar.
I would start with the UIScrollViewDelegate.
Since the UITableViewDelegate
is a subclass of the UIScrollViewDelegate,
you can, in your view controller, set your UITableView
's delegate to self.
With this, you can now listen to scrolling movements.
When the UITableView
is at the top and the user is scrolling down, I would recommend to take a screenshot of the status bar, add it to a UIView
, and move that said view up at the same speed as the UITableView
is moving (see the UIScrollViewDelegate
documentation for help). Likewise, when scrolling to the top, I would have the view move down to the position of the status bar, then remove the view, and set the status bar visible.
With this method, you have the appearance of the status moving up and down with the table view.

- 711
- 1
- 5
- 22
Try This
func scrollViewDidScroll(scrollView: UIScrollView)
{
UIApplication.sharedApplication().statusBarHidden = true
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView)
{
UIApplication.sharedApplication().statusBarHidden = false
}

- 1,391
- 12
- 21
-
-
Try this : http://stackoverflow.com/questions/30271271/how-to-hide-the-status-bar-programmatically-in-ios-8 – Jacky Shek Mar 09 '16 at 06:01