禁用iPhone中键盘的方向 [英] Disable orientation for Keyboard in iPhone

查看:113
本文介绍了禁用iPhone中键盘的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要支持键盘视图的纵向模式。



因为,我有一个支持所有方向的UIViewController。它提供了一个仅支持纵向方向的视图控制器,该视图具有文本字段。当TextField成为第一响应者时,键盘视图会加速。现在,如果我更改设备方向,键盘会将其方向更改为横向。



如何将键盘保持在纵向方向?


<试试这个:



创建一个名为 UIInterfaceOrientation的iVar previousOrientation 解决方案

$ c>。



当你说 [textField becomeFirstResponder]; add:

  [viewController shouldAutoRotateToInterfaceOrientation:UIInterfaceOrientationPortrait]; 

//将previousOrientation设置为
previousOrientation = viewController.interfaceOrientation

//这可以防止它离开纵向
[[UIDevice] currentDevice] endGeneratingDeviceOrientationNotifications];

然后在 [textField resignFirstResponder] 中,用户关闭键盘或按回车键;
您可以恢复原来的方向。

  [ViewController shouldAutoRotateToInterfaceOrientation:previousOrientation]; 

//重新打开通知,以便它能够再次旋转
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];


I need to support only Portrait mode for Keyboard view.

Because, I have an UIViewController that supports all orientations. It presents an View controller which supports only Portrait orientation and this view has an Text Field. When TextField becomes first responder Keyboard view is poped up. Now, if I change the device orientation, keyboard changes its orientation to Landscape.

How do I keep the keyboard in Portrait orientation?

解决方案

Try this:

Create an iVar called UIInterfaceOrientation previousOrientation.

When you say [textField becomeFirstResponder]; add:

[viewController shouldAutoRotateToInterfaceOrientation:UIInterfaceOrientationPortrait];

// Set the previousOrientation to whatever it was
previousOrientation = viewController.interfaceOrientation

// This prevents it from leaving portrait orientation
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

Then in [textField resignFirstResponder], when the user closes the keyboard or presses enter; You can revert to the original orientation.

[ViewController shouldAutoRotateToInterfaceOrientation:previousOrientation];

// Turn the notifications back on so that it will be able to rotate again
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

这篇关于禁用iPhone中键盘的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆