问题描述
我的应用程序一直运行良好,直到我尝试使用ios 6 SDK进行一些更改
my app has been working fine until I've tried making some changes using the ios 6 SDK
该应用程序99%的时间以纵向模式运行。这仅限于允许在info.plist中使用portait模式
The app runs in portrait mode 99% of the time. This has been constrained by only allowing portait mode to be available in the info.plist
有一个视图控制器需要以横向模式显示。这是通过简单地将视图旋转90度来手动实现的,如下所示:
There is one view controller which needs to be shown in landscape mode. This is achieved "manually" by simply rotating the view by 90 degrees, like so:
self.view.transform = CGAffineTransformMakeRotation(3.14159/2);
这在iOS 6中仍然有效。
This still works fine in iOS 6.
但是,此视图控制器有一些文本字段。当用户点击一个时,它会显示键盘。由于我只旋转了视图(而不是实际更改了设备的方向),因此键盘以纵向模式显示,这是不行的。
However, this view controller has some text fields. When the user taps one it shows the keyboard. Since I've only rotated the view (and not actually changed the orientation of the device), the keyboard comes out in portrait mode, which is no good.
在以前版本的iOS中,我将状态栏的方向设置为横向,并且作为副产品,这会将键盘设置为横向,如下所示:
In previous versions of iOS, I set the orientation of the status bar to be landscape, and as a byproduct, this would set the keyboard to be landscape as well, like this:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
然而,这已经停止在iOS 6上工作。
However, this has stopped working for iOS 6.
我已经阅读了一百万个堆栈溢出试图让它工作,但仍然没有运气。
I have read a million stack overflows trying to get this to work, but still have no luck.
推荐答案
改变键盘方向和转换是一个困难的部分,并不是一个好的解决方案(特别是当它改变状态栏方向时)。
Changing the keyboard orientation and transform is an difficult part and not a good solution(especially when it changes status bar orientations).
更好的解决方案是允许应用程序支持所有方向。
Better solutions is to allow application to support all orientations.
在旋转支持中实现ViewControllers中的Orientation委托。
Implement the Orientation delegates inside your ViewControllers asper the rotation support.
仅支持横向
-(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;
}
这篇关于仅设置键盘方向(iOS 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!