【问题标题】:How to disable the emoji keyboard in iOS 7?如何在 iOS 7 中禁用表情符号键盘?
【发布时间】:2014-09-15 15:11:38
【问题描述】:

我想以编程方式禁用表情符号键盘。请让我知道我该怎么做?

我尝试使用以下代码,

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:@"/private/var/mobile/Library/Preferences/com.apple.Preferences.plist"];
[dict setObject:[NSNumber numberWithBool:NO] forKey:@"KeyboardEmojiEverywhere"];

但没有运气... :(

【问题讨论】:

    标签: ios emoji


    【解决方案1】:

    您可以简单地将 UITextField 或 UITextView 的属性 keyboardType 设置为 UIKeyboardTypeASCIICapable。这会为此 UI 元素禁用表情符号键盘。

    这在中文中可能不起作用,但我们也有解决方法:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        if (IS_OS_7_OR_LATER) {
            if ([textField isFirstResponder]) {
                if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) { // In fact, in iOS7, '[[textField textInputMode] primaryLanguage]' is nil
                    return NO;
                }
            }
        } else {
            if ([[[UITextInputMode currentInputMode] primaryLanguage] isEqualToString:@"emoji"] ) {
                return NO;
            }
        }
    
        return YES;
    }
    

    用户将无法输入任何表情符号图标。

    【讨论】:

    • 如果我们使用 UIKeyboardTypeASCIICapable ,多语言支持是不可能的:(。我想支持多语言,但表情符号应该被禁用。
    • currentInputMode 在 ios 7 中已弃用。
    【解决方案2】:

    接受的答案效果很好,但是在 iOS 7 中不推荐使用 currentInputMode。相反,您可以使用 this SO thread 中所述的 textInputMode:

    +(BOOL)isEmojiInput:(UITextView)aTextView
    {
        return [aTextView textInputMode] == nil;
    }
    

    【讨论】:

      【解决方案3】:

      虽然问题已经很老了, 我遇到了同样的问题,并且在这个小技巧加载此页面时能够解决它:

      在 Interface Builder Xcode 8.2.1 中简单地选择数字和标点符号

      输出没有表情符号键盘=D

      我相信它会帮助某人 =)

      【讨论】:

        猜你喜欢
        • 2014-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多