解决方案
这是针对此问题的
返回表情符号"的示例代码UITextInputMode
.
////ViewController.swift//键盘信息////由 Richard Stelling 于 2019 年 9 月 30 日创建.//版权所有 © 2019 Richard Stelling.版权所有.//导入 UIKit类TestButton:UIButton,UIKeyInput {var hasText: Bool = truefunc insertText(_ text: String) { print("(text)") }函数 deleteBackward() {}覆盖 var canBecomeFirstResponder: Bool { return true }覆盖 var canResignFirstResponder: Bool { return true }覆盖 var textInputMode: UITextInputMode?{对于 UITextInputMode.activeInputModes 中的模式 {如果 mode.primaryLanguage == "emoji" {返回模式}}返回零}}
在 iOS 12 上运行此代码会将键盘设置为系统表情符号键盘,但在 iOS 13 上没有任何影响.
这是一个已知的错误吗?有解决方法吗?
更新
注意:确保您已启用表情符号键盘.
这似乎是 iOS 13 的错误,解决方法(对于设备,这不会影响模拟器)是覆盖 textInputContextIdentifier
属性并返回非零值.
////ViewController.swift//键盘信息////由 Richard Stelling 于 2019 年 9 月 30 日创建.//版权所有 © 2019 Richard Stelling.版权所有.//导入 UIKit类TestButton:UIButton,UIKeyInput {var hasText: Bool = true覆盖 var textInputContextIdentifier: String?{ "" }//返回非 nil 以显示 Emoji 键盘¯\_(ツ)_/¯func insertText(_ text: String) { print("(text)") }函数 deleteBackward() {}覆盖 var canBecomeFirstResponder: Bool { return true }覆盖 var canResignFirstResponder: Bool { return true }覆盖 var textInputMode: UITextInputMode?{对于 UITextInputMode.activeInputModes 中的模式 {如果 mode.primaryLanguage == "emoji" {返回模式}}返回零}}
<块引用>
感谢 blld 的回答.
Solution
Here is a full solution/work around for this issue, please up vote Blld's answer as well because this was the vital bit of info needed!
Alternative titles to aid search
UITextInputMode.primaryLanguage
to emojiPrior to ios13 returning the UITextInputMode
with primaryLanguage
that equaled "emoji" would default to showing the Emoji Keyboard (see image below).
Example code for returning the "emoji" UITextInputMode
.
//
// ViewController.swift
// Keyboard Info
//
// Created by Richard Stelling on 30/09/2019.
// Copyright © 2019 Richard Stelling. All rights reserved.
//
import UIKit
class TestButton: UIButton, UIKeyInput {
var hasText: Bool = true
func insertText(_ text: String) { print("(text)") }
func deleteBackward() {}
override var canBecomeFirstResponder: Bool { return true }
override var canResignFirstResponder: Bool { return true }
override var textInputMode: UITextInputMode? {
for mode in UITextInputMode.activeInputModes {
if mode.primaryLanguage == "emoji" {
return mode
}
}
return nil
}
}
Running this code on iOS 12 will set the keyboard to the system Emoji Keyboard, but on iOS 13 it has no affect.
Is this a known bug? Is there a workaround?
Updates
NB: Make sure you have the Emoji keyboard enabled.
This seems to be an iOS 13 bug, the work around (for devices, this does not affect the Simulator) is to override the textInputContextIdentifier
property and return a non-nil value.
//
// ViewController.swift
// Keyboard Info
//
// Created by Richard Stelling on 30/09/2019.
// Copyright © 2019 Richard Stelling. All rights reserved.
//
import UIKit
class TestButton: UIButton, UIKeyInput {
var hasText: Bool = true
override var textInputContextIdentifier: String? { "" } // return non-nil to show the Emoji keyboard ¯\_(ツ)_/¯
func insertText(_ text: String) { print("(text)") }
func deleteBackward() {}
override var canBecomeFirstResponder: Bool { return true }
override var canResignFirstResponder: Bool { return true }
override var textInputMode: UITextInputMode? {
for mode in UITextInputMode.activeInputModes {
if mode.primaryLanguage == "emoji" {
return mode
}
}
return nil
}
}
Thanks to blld for his answer.
这篇关于在 iOS 13 上默认显示系统表情符号键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!