试图在横向模式而不是纵向模式下显示键盘在iOS 8中
我有一个使用iOS7制作的iPad项目,它在横向模式下显示一个视图控制器。在这个视图控制器上,有一个UITextField,它是屏幕上的第一个响应者,因此当用户进入这个屏幕时,键盘应该被呈现出来,它就是这样做的。然而,问题在于,在iOS 8中以纵向模式显示视图控制器时,键盘以纵向模式显示。我如何解决此问题,以便键盘的方向与视图控制器一致(它仍然以横向模式正确显示)?只是为了记录,这个视图尤其是使用.xib文件,而不是在故事板中。试图在横向模式而不是纵向模式下显示键盘在iOS 8中
下面是我的代码:
MyLandscapeViewController.m
相关方法:
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
- (void)viewDidUnload {
[self setKeyboardButton:nil];
[super viewDidUnload];
}
对于视图控制器,I创建自定义导航控制器:
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工作?
在此先感谢所有回复的人。
试试这个。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
[UIViewController attemptRotationToDeviceOrientation];
}
将第一行('[[UIDevice currentDevice] setValue:...];')添加到viewWillAppear中,为我在iOS 8中修复键盘方向,谢谢! – JasonJasonJason 2015-04-22 22:08:26
我用'[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft] forKey:@“orientation”];'解决我的问题,但要小心,如果你想使用'UIDeviceOrientationLandscapeLeft'而不是'UIInterfaceOrientationLandscapeLeft',你必须知道'UIDeviceOrientationLandscapeLeft'等于'UIInterfaceOrientationLandscapeRight',反之亦然! – 2015-05-08 09:26:15
你可以试试[UIViewController中attemptRotationToDeviceOrientation在viewDidAppear并设置第一个响应者在紧接本 – brendan 2014-09-26 23:28:41
感谢布兰登您的回复。我尝试过,但不幸的是它没有奏效。 – syedfa 2014-09-27 18:16:50