【发布时间】:2014-09-26 22:52:43
【问题描述】:
我有一个使用 iOS7 制作的 iPad 项目,它在某一时刻以横向模式显示视图控制器。在这个视图控制器上,有一个 UITextField 是屏幕上的第一响应者,因此当用户来到这个屏幕时,应该立即显示键盘,它确实如此。
但是,问题是在 iOS 8 中,当视图控制器以横向模式显示时,键盘以纵向模式显示。我该如何纠正这个问题,以便键盘的方向与视图控制器(它仍然以横向模式显示,正确)?只是为了记录,这个视图特别是使用 .xib 文件,而不是在情节提要中。
下面是我的代码:
MyLandscapeViewController.m
相关方法:
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
- (void)viewDidUnload {
[self setKeyboardButton:nil];
[super viewDidUnload];
}
对于视图控制器,我创建了一个自定义导航控制器:
MyNavigationController.m
-(BOOL)shouldAutorotate{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
在我的应用程序中,它的调用如下:
MyLandscapeViewController *myView = [[MyLandscapeViewController alloc] initWithNibName:@"MyLandscapeViewController" bundle:nil];
MyNavigationController *navigationController = [[MyNavigationController alloc] initWithRootViewController:myView];
[self.rootViewController presentViewController:navigationController animated:YES completion:nil];
我需要进行哪些更改才能使其在 iOS 8 上运行?
【问题讨论】:
-
您可以在 viewDidAppear 中尝试 [UIViewController attemptRotationToDeviceOrientation] 并在此之后立即设置第一响应者
-
感谢布伦丹的回复。我试过这个,但不幸的是它没有用。
标签: ios objective-c uiviewcontroller uinavigationcontroller