简体   繁体   中英

View controller not autoresizing when status bar reappears

With the status bar initially visible, I add a subview and hide the status bar:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[myController.view addSubview:anotherController.view];

In this view there is a button to toggle the status bar visibility, but when I set statusBarHidden to NO again, the view controller's view doesn't auto resize to take into account the status bar, and as a result the view is pushed down and cut off by 20px. I've set all the appropriate resizing masks to the view and also tried auto-layout, but neither seem to work. I'd like my view to resize automatically when showing/hiding status bar without manually setting its frame.

Update

Instead of adding it the root view controller's view, I've pushed it onto the stack of my navigation controller, and hidden the status bar and navigation bar. I then give the user the option to toggle only the status bar. However the problem still remains and the view is pushed and cut off by 20px when the status bar reappears.

But when I rotate the device, everything is in its place - only if I rotate the device after the status bar has been hidden.

How is myController added to the window? Assuming that myController is the rootViewController of your window, than this controller should resize correctly when displaying / hiding the statusBar. The view of anotherController should be added in another way, than just adding its view. But still, if you give that view the correct resizing flags, it should also resize. But it would be better, if you push that controller on a navigationController, or if you set it as the new rootViewController.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM