Status bar rotates separated from UIWindow

孤街浪徒 提交于 2019-12-11 04:48:41

问题


I have to create application with two UIWindow (please, don't ask why). First UIWindow's rootViewController supports all orientations. Second one - only portrait and upside down. So application delegate code looks like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // part one
    self.windowOne = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.windowOne.rootViewController = [[ViewControllerOne alloc] init]; // supports all orientations
    self.windowOne.rootViewController.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.png"]] autorelease];

    [self.windowOne makeKeyAndVisible];
    //~part one
    // part two
    self.windowTwo = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.windowTwo.rootViewController = [[ViewControllerTwo alloc] init]; // supports only portrait and upside down
    self.windowTwo.rootViewController.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image2.png"]] autorelease];

    [self.windowTwo makeKeyAndVisible];
    //~part two
    return YES;
}

If only one of two parts is active (second one is commented) - everything is ok. But if windowOne has become key and visible before windowTwo, windowTwo rotates as ViewControllerTwo allows, but status bar behaves really weird: it rotates like windowOne is key and visible.

Is there any option to make status bar rotating as ViewControllerTwo says?


回答1:


Albeit its a hack to me but what you could try is the following:

In your view controllers shouldAutorotateToInterfaceOrientation (for iOS5) or shouldAutorotate (as for iOS6) method add the following code line:

[[UIApplication sharedApplication] setStatusBarOrientation: interfaceOrientation animated: YES];

and test out how the app behaves after that.

to get the interface-orientation in the (new for iOS6) shouldAutorotate method do the following:

UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

I didn't test this all out for myself, but it could work.

(Check out some post on how to support autorotation under iOS6)



来源:https://stackoverflow.com/questions/13029858/status-bar-rotates-separated-from-uiwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!