简体   繁体   中英

iOS7 : View talking portrait frame when loading child view controller from landscape mode

I am creating iPad Universal application with UITabBarViewController. When I navigate to First tab screen from Login view while my Login screen is in portrait mode. FirstView controller load properly and rotation work nicely.

But if I rotate device on Landscape mode then doLogin I navigate to First tab View then UI messed up as root view still taking portrait frame.

This however works nicely on iOS 8. This is how UI looks on iOS 8(Correct UI)

在此处输入图片说明

This is how UI looks on iOS7(incorrect UI) 在此处输入图片说明

Here is my code:

tabBarController = [[UITabBarController alloc]init];

FirstViewController *vc = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:vc, nil];
[tabBarController setViewControllers:viewControllersArray animated:YES];

[self addChildViewController:tabBarController];
[self.view addSubview:tabBarController.view];

I am using this code on LoginViewController. LoginViewController is my RootViewController In didFinishLaunchWithOption i am setting LoginController as a rootViewcontroller using below code: [self.window setRootViewController:self.loginviewController];

I'm having a similar problem too, I'm adding my view to a landscape nav controller but the view frame size is portrait. I don't know if there is a better way around this than what i ended up doing, but this was my solution.

I put the following in the viewDidLoad of the view controller thats being added.

// Hack because iOS 7 was loading in portrait instead of landscape
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8)
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.height, self.view.frame.size.width);

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