开发者

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 = [[Log开发者_Python百科inViewController 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜