When installing setStatusBarHidden: in an iOS v5 application. The empty space remains. Is this correct?

I wanted to switch the statusBar in my universal iOS v5 application.

But found that others seem to have UIViews (in my case, subViews added to the main view), just return the 20px left from the hidden statusBar if you then rotate the device (I use the simulator)

And my views are fulfilled programmatically.

I tried some of the suggestions found in googling, but none of them worked. ie autosave / mask change, wants FullScreenLayout, setNeedsLayout, in IB 'use full screen.'

Finally, I realized that I set the frame height to 0 and heights height for my views in [[UIScreen mainScreen] applicationFrame] size.height

What I came up with: set the frame height -20, and the height of the frame at [[UIScreen mainScreen] applicationFrame] size.height + 20

In viewDidLoad.

CGRect theDeviceRect= [[UIScreen mainScreen] applicationFrame]; newMap.frame = CGRectMake(0, -20, theDeviceRect.size.width, theDeviceRect.size.height+20); 

I also have this in willAnimateRotationToInterfaceOrientation: delegate.

Now when I switch the status bar with:

 - (void) toggleStatusBarAction:(id)sender{ BOOL istathidden= [[UIApplication sharedApplication] isStatusBarHidden]; [[UIApplication sharedApplication] setStatusBarHidden:!istathidden withAnimation:UIStatusBarAnimationFade]; } 

Everything works as expected. But I wanted to see if this solution is good or a bad way to do it, and if I am missing something ?:

Thank you very much in advance. Mh

+4
source share
1 answer

What am I doing:

After this code:

 [[UIApplication sharedApplication] setStatusBarHidden:NO]; 

I immediately execute:

 CGRect originalFrame = self.view.frame; originalFrame.origin.y = 20.0; self.view.frame = originalFrame; 

This will β€œupdate” the frame to the correct position. Not the best solution, but it works.

In your example, you may need to dynamically set y to 0 or 20 depending on istathidden.

Change to 2 / SEP / 2012: Best solution when disabling the modal view controller:

 [[UIApplication sharedApplication] setStatusBarHidden:NO]; self.view.frame = [[UIScreen mainScreen] applicationFrame]; 
+7
source

Source: https://habr.com/ru/post/1388462/


All Articles