0

I have the code below where I am hiding the status bar but I want to be able to show the status bar when the user decides to record the screen. How would I be able to do that?

 Edit : I added the isCaptured property in a if statement but
 when the screen recording is happening the status bar comes back 
 white and doesnt show the red bar for some reason. Anyone know why?

override var prefersStatusBarHidden: Bool {

if UIScreen.main.isCaptured == true {
    print("show status bar")
    return false
} else {
print("hide status bar")

        return true


}
xcode22
  • 118
  • 1
  • 9
  • Sorry but that's completely different from your original question. There was nothing about red in the original question. You asked how to make the status bar come back from being hidden and I answered that. – matt Mar 05 '20 at 22:47
  • I know but when the status bar comes back and is recording it usually is red. Right now its just a blank white bar on the top. – xcode22 Mar 05 '20 at 22:49
  • Does this help? https://stackoverflow.com/questions/14273824/how-to-display-a-red-status-bar-when-the-home-button-is-pressed You are supposed to have background audio and recording in your modes. – matt Mar 05 '20 at 22:55

2 Answers2

1

Call setNeedsStatusBarAppearanceUpdate. This will cause prefersStatusBarHidden to be called again, and this time you return false.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Where would I call `setNeedsStatusBarAppearanceUpdate`? The user is gonna use the iphone screen recorder when you swipe up and press the screen record button. How would I know when the user presses the screen record button and then show the status bar accordingly? Thanks. – xcode22 Mar 05 '20 at 22:14
  • @xcode22 check this https://stackoverflow.com/a/53427172/1244403 – Harish Mar 05 '20 at 22:18
  • @Harish I added the isCaptured property and when I record the screen the status bar comes back white and not with the red bar. Any idea why that happens? I updated the code in the OP. – xcode22 Mar 05 '20 at 22:28
  • why do you need it in red? is that your requirement? – Harish Mar 05 '20 at 22:33
  • it could be any color the bar is white right now and doesnt really give the user the impression the screen is recording. – xcode22 Mar 05 '20 at 22:40
0

just call setNeedsStatusBarAppearanceUpdate() on your view controller – that will force prefersStatusBarHidden to be read again, at which point you can return a different value. If you want, your call to setNeedsStatusBarAppearanceUpdate() can actually be inside an animation block, which causes the status bar to hide or show in a smooth way.

Harish
  • 2,496
  • 4
  • 24
  • 48