简体   繁体   English

如何在iOS6中更改键盘方向

[英]How to change keyboard orientation in ios6

I have a problem. 我有个问题。 I am developing a game like ludo. 我正在开发类似ludo的游戏。 In this i have to create text field, for all players participating in game. 为此,我必须为所有参与游戏的玩家创建文本字段。 These players may be in all directions of iPad. 这些播放器可能在iPad的各个方向。 And for filling answer in this text field user can use keyboard of iPad. 而在该文本字段中填写答案的用户可以使用iPad的键盘。 But problem is that I am unable to open keyboard form all sides of iPad. 但是问题是我无法从iPad的各个侧面打开键盘。

I am using- 我在用-

[[UIApplication sharedApplication] setStatusBarOrientation:toInterfaceOrientation animated:YES];

for changing orientation of keyboard. 用于更改键盘的方向。 It is working in lower ios versions. 它在较低的ios版本中运行。 But in ios6 it is not working properly. 但是在ios6中,它无法正常工作。 Any help will be appreciated. 任何帮助将不胜感激。

Have you written orientation methods for ios 6? 您是否为ios 6编写了定位方法? and have you allow your all orientation in .info plist file? 并允许您在.info plist文件中使用所有方向吗?

If not then it is here write down.. 如果没有,那就在这里写下来。

-(BOOL)shouldAutorotate
{
   return YES;
}
-(NSInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskAll;
}

Then try to orient your device and let me know is it working or not...! 然后尝试调整设备的方向,让我知道它是否正常工作!!

Happy coding! 编码愉快!

Never return YES always in 永远不要在任何情况下返回YES

-(BOOL)shouldAutorotate
{
   return YES;
}

In AppDelegate write code 在AppDelegate中编写代码

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"_rotation"];

And change above method like this 然后像这样改变上面的方法

-(BOOL)shouldAutorotate
 {
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"_rotation"];
 }

Now where you want to change orientation in application. 现在,您要在应用程序中更改方向。 Set above flag for _rotation to NO and after calling method of statusBarOrientation again set this to YES. 将_rotation的上述标志设置为NO,并在调用statusBarOrientation的方法后再次将其设置为YES。 This is because statusBarOrientation method will work only if shouldAutorotate method will return NO. 这是因为statusBarOrientation方法仅在shouldAutorotate方法返回NO时才有效。

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"_rotation"];
[[UIApplication sharedApplication] setStatusBarOrientation:toInterfaceOrientation animated:YES];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"_rotation"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM