我在横向模式下呈现ModalViewController有些困难.基本上它以正确的界面方向显示,并且仅在设备处于横向模式时旋转,但视图控制器的作用就像它处于纵向模式一样.
我正在呈现这样的模态
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
[self.window.rootViewController presentModalViewController:lvc animated:NO];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在LoginViewController中
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)
几次轮换后的日志结果:
2012-03-06 13:51:49.308 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, …Run Code Online (Sandbox Code Playgroud)