禁用 iPhone 中键盘的方向

Disable orientation for Keyboard in iPhone(禁用 iPhone 中键盘的方向)
本文介绍了禁用 iPhone 中键盘的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I need to support only Portrait mode for Keyboard view.

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

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.

如何让键盘保持纵向?

推荐答案

试试这个:

创建一个名为UIInterfaceOrientation previousOrientation的iVar.

Create an iVar called UIInterfaceOrientation previousOrientation.

当你说 [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]中,当用户关闭键盘或回车时;您可以恢复到原来的方向.

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 中键盘的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

No resource found that matches the given name: attr #39;android:keyboardNavigationCluster#39;. when updating to Support Library 26.0.0(找不到与给定名称匹配的资源:attr android:keyboardNavigationCluster.更新到支持库 26.0.0 时) - IT屋-程序员软
How to resize UITextView on iOS when a keyboard appears?(出现键盘时如何在iOS上调整UITextView的大小?)
How to reliably detect if an external keyboard is connected on iOS 9?(如何可靠地检测 iOS 9 上是否连接了外部键盘?)
How do I dismiss the iOS keyboard?(如何关闭 iOS 键盘?)
Is possible to simulate touch event using an external keyboard on ios jailbroken?(是否可以在 ios 越狱后使用外部键盘模拟触摸事件?)
Numeric Soft Keyboard on Android(Android 上的数字软键盘)