简体   繁体   中英

iOS 8 status bar background orientation in landscape mode

In iOS8, in the viewDidLoad method of my viewController I set the main view programatically using the following code:

CGRect appRect = [[UIScreen mainScreen] applicationFrame];
rootView = [[RootView alloc] initWithFrame: appRect];
[self setView: rootView];

The app only runs in landscape left mode (I control this from the plist file of the application). This is what the view looks like after it set it: 在此处输入图片说明

Even though the app is in landscape mode, the white bar that should be under the status bar appears as if the app is in portrait mode. Any thoughts on what might be causing this?

Edit: Running this:

NSLog(@"%@",NSStringFromCGRect([[UIApplication sharedApplication] statusBarFrame]));

outputs: {{0, 0}, {1024, 20}}

Edit: I added a background color for the root view:

rootView.backgroundColor = [UIColor greenColor];

This is what the app looks like now: 在此处输入图片说明

The problem in my case was that in my appdelegate the my - (void)applicationDidFinishLaunching:(UIApplication *)application method: I wasn't setting the root view controller. Instead I was doing this:

viewController = [[BoardViewController alloc] init];
[window makeKeyAndVisible];
[window addSubview: [viewController view]];

Once I changed that the root view frame covered the whole window and the status bar background was where it was supposed to be:

viewController = [[BoardViewController alloc] init];
[window makeKeyAndVisible];
window.rootViewController = viewController;

I got the idea from this answer: iOS 8 - Launching the application in Landscape mode

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