所以我正在开发一个 iOS 键盘扩展,我希望我的返回按钮文本根据 returnKeyType
进行更改,但是,这个 API 似乎无法在键盘扩展上正常工作。
我有一个带有一些 UITextField 的托管应用程序,当我使用内置的英文键盘时,它的返回键根据我为 UITextField 设置的 returnKeyType
正确更改。
但是对于我自己的键盘扩展,我运行了一个调试器并且我总是看到
self.textDocumentProxy.returnKeyType = .default
我的逻辑很简单,我有这个函数来改变返回文本
public func changeReturnText() {
var text: String
let returnKeyType = self.textDocumentProxy.returnKeyType
SpeedLog.log("Return Key Type: \(returnKeyType?.rawValue ?? -1)")
switch returnKeyType ?? .default {
case .continue:
text = "繼續"
case .done:
text = "完成"
case .go, .google, .yahoo:
text = "前往"
case .search:
text = "搜尋"
case .next:
text = "下一個"
case .send:
text = "送出"
default:
text = "換行"
}
returnKey.text = text
}
然后我将该函数放入我的 init()
我能够针对此运行调试器,但是 self.textDocumentProxy.returnKeyType
总是返回 .default
即使我设置了 UITextField returnKeyType
到 .done
而内置的英文键盘工作正常。
有什么想法吗?非常感激。
最佳答案
正如 Ben Pious 所指出的,显然我过早地调用了 textDocumentProxy
。并注意 textDocumentProxy
仅在帧非零后可用。
关于ios - UITextInputTraits.returnKeyType 在键盘扩展中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48372076/