仅设置键盘方向(iOS 6)

我的应用程序一直工作正常,直到我已经尝试使用ios 6 SDK进行一些更改

该应用程序运行在肖像模式99%的时间。 由于只允许在info.plist中使用portait模式,所以受到了限制

有一个视图控制器需要以横向模式显示。 这是通过简单地将视图旋转90度来“手动”实现的,如下所示:

self.view.transform = CGAffineTransformMakeRotation(3.14159/2); 

这在iOS 6中仍然可以正常工作。

但是,这个视图控制器有一些文本字段。 当用户点击一个显示键盘。 由于我只旋转了视图(并没有真正改变设备的方向),所以键盘出现在肖像模式下,这是不好的。

在以前的iOS版本中,我将状态栏的方向设置为横向,并且作为副产品,这会将键盘设置为横向,如下所示:

 [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO]; 

但是,这已停止iOS 6的工作。

我已经读了一百万个堆栈溢出试图让这个工作,但仍然没有运气。

改变键盘方向和转换是一个困难的部分,而不是一个好的解决scheme(尤其是当它改变状态栏的方向)。

更好的解决scheme是允许应用程序支持所有的方向。

在这里输入图像说明

根据旋转支持,在您的ViewControllers中实现方向代表。

仅支持景观

 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight ; } - (BOOL)shouldAutorotate { return NO; } 

仅支持肖像

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }