ios 在 UITextView 上以编程方式禁用 iOS8 Quicktype 键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25951274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable iOS8 Quicktype Keyboard programmatically on UITextView
提问by rihe
I'm trying to update an app for iOS8, which has a chat interface, but the new Quicktype keyboard hides the text view, so I would like to turn it off programmatically or in interface builder.
我正在尝试为 iOS8 更新一个具有聊天界面的应用程序,但新的 Quicktype 键盘隐藏了文本视图,因此我想以编程方式或在界面构建器中将其关闭。
Is it possible somehow or only the users can turn it off in the device settings?
是否有可能以某种方式或只有用户可以在设备设置中将其关闭?
I know there is a question/answer which solves this problem with a UITextfield
, but I need to do it with a UITextView
.
我知道有一个问题/答案可以用 a 解决这个问题UITextfield
,但我需要用UITextView
.
回答by mihai
You may disable the keyboard suggestions / autocomplete / QuickType for a UITextView which can block the text on smaller screens like the 4S as shown in this example
您可以禁用 UITextView 的键盘建议/自动完成/QuickType,它可以阻止小屏幕上的文本,如本例所示的 4S
with the following line:
与以下行:
myTextView.autocorrectionType = UITextAutocorrectionTypeNo;
And further if youd like to do this only on a specific screen such as targeting the 4S
此外,如果您只想在特定屏幕上执行此操作,例如针对 4S
if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (screenHeight == 568) {
// iphone 5 screen
}
else if (screenHeight < 568) {
// smaller than iphone 5 screen thus 4s
}
}
回答by Nikita Kukushkin
For completeness sake I would like to add that you can also do this in the Interface Builder
.
为了完整起见,我想补充一点,您也可以在Interface Builder
.
To disable Keyboard Suggestions on UITextField
or UITextView
— in the Attributes Inspector
set Correction
to No
.
在设置为UITextField
或 中禁用键盘建议。UITextView
Attributes Inspector
Correction
No
回答by DZenBot
I've created a UITextView category class with the following method:
我使用以下方法创建了一个 UITextView 类别类:
- (void)disableQuickTypeBar:(BOOL)disable
{
self.autocorrectionType = disable ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
if (self.isFirstResponder) {
[self resignFirstResponder];
[self becomeFirstResponder];
}
}
I wish there was a cleaner approach tho. Also, it assumes the auto-correction mode was Default
, which may not be always true for every text view.
我希望有一种更清洁的方法。此外,它假定自动更正模式为Default
,对于每个文本视图可能并不总是如此。
回答by Rao
In Swift 2:
在 Swift 2 中:
myUITextField.autocorrectionType = UITextAutocorrectionType.No
回答by yo2bh
In Swift 4.x:
在 Swift 4.x 中:
myUTTextField.autocorrectionType = .no
回答by Rance
As others have said, you can use:
正如其他人所说,您可以使用:
textView.autocorrectionType = .no
but I've also noticed people struggling with actually making the autocomplete bar swap out, since if the textView is already the firstResponder when you change its autocorrectionType, it won't update the keyboard. Instead of trying to resign and reassign the firstResponder status to the textView to effect the change, you can simply call:
但我也注意到人们在实际更换自动完成栏时苦苦挣扎,因为如果 textView 在您更改其 autocorrectionType 时已经是 firstResponder,则它不会更新键盘。与其尝试辞职并将 firstResponder 状态重新分配给 textView 以实现更改,您只需调用:
textView.reloadInputViews()
and that should hide the autocomplete bar. See https://developer.apple.com/documentation/uikit/uiresponder/1621110-reloadinputviews
这应该隐藏自动完成栏。请参阅https://developer.apple.com/documentation/uikit/uiresponder/1621110-reloadinputviews