[英]Disable orientation for Keyboard in iPhone
我只需要支持键盘视图的纵向模式。
因为,我有一个支持所有方向的UIViewController。 它提供了一个仅支持纵向方向的视图控制器,该视图具有文本字段。 当TextField成为第一响应者时,键盘视图会加速。 现在,如果我更改设备方向,键盘会将其方向更改为横向。
如何将键盘保持在纵向方向?
如果您只需要纵向方向,您可以通过以下方式禁用自动旋转:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
尝试这个:
创建名为UIInterfaceOrientation UIInterfaceOrientation previousOrientation
的iVar。
当你说[textField becomeFirstResponder];
加:
[viewController shouldAutoRotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
// Set the previousOrientation to whatever it was
previousOrientation = viewController.interfaceOrientation
// This prevents it from leaving portrait orientation
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
然后在[textField resignFirstResponder]
,当用户关闭键盘或按回车键时; 您可以恢复原始方向。
[ViewController shouldAutoRotateToInterfaceOrientation:previousOrientation];
// Turn the notifications back on so that it will be able to rotate again
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.