我在横向模式下呈现 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;
}
在登录视图控制器中
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
几次轮换后的日志结果:
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, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.313 OrientationTest[3132:207] {{0, 20}, {1024, 748}}
2012-03-06 13:51:49.314 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:49.315 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:51.647 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:51.648 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.481 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.482 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.897 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.898 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
基本上,loginViewController 的行为就像处于纵向模式一样。我在此视图上有两个文本字段,当我点击其中之一时,我想向上移动视图,以便键盘不会显示在文本字段上。为了做到这一点,我必须修改frame.origin.x而不是y,因为轴是反转的(视图的行为就像肖像),这导致了很多问题。
Edit :
如果我将 LoginViewController 上的模式呈现样式更改为 UIModalPresentationPageSheet ,它会按预期工作,因此仅全屏模式会出现一些问题
第二次编辑:
我已将代码简化为基础内容。我什至不再提供模式视图控制器,只是将该视图控制器初始化为根视图控制器,但这种情况仍然发生。
应用程序委托:
- (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];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
在我的视图控制器中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"%@",NSStringFromCGRect( self.view.frame));
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}