SideSwipe
SideSwipe

Reputation: 559

UIInterfaceOrientation rotation in subview not working

In my App I use a UITabbarController, which rotates perfectly to all UIInterfaceOrientations in all viewcontrollers. But when I add an UIView to the UIWindow afterwards it will not be added in the current UIInterfaceOrientation, but always in UInterfaceOrientationPortrait (which is default for the app). It won't rotate to a new orientation also. I add the ViewController by using:

LoginViewController *loginViewController = [[LoginViewController alloc] init];
[self.window addSubview:[loginViewController view]];

I have

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    NSLog(@"%@", @"YES IT WILL!");
}

in LoginViewController.m but there will never be logged anything. Any idea why the subview won't rotate?

SideSwipe

EDIT: Found the solution: Apparently UIWindow should only have one subview, not more, otherwise things will mess up, so i call:

LoginViewController *loginViewController = [[LoginViewController alloc] init];
[tabBarController presentModalViewController:loginViewController animated:YES];

instead, which will autorotate the loginviewcontrollers view just fine.

Upvotes: 2

Views: 1426

Answers (2)

Derek Li
Derek Li

Reputation: 3111

I have a view inside another view, when rotation happened, only the parent willRotateToInterfaceOrientation got called, so what I did is add [self.subViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; to parent's willRotateToInterfaceOrientation method.

Upvotes: 1

alloc_iNit
alloc_iNit

Reputation: 5183

As you are adding a new subview to window, you have to make the window rotate too.

Upvotes: 0

Related Questions