在我的 Apple Watch 应用程序中,我需要输入文本,那么有没有办法使用 VoiceOver 或其他方式在我的应用程序中输入文本?
因为我发现 WKInterfaceController 中的对象都不支持像 UITextfield 或 UITextview 一样的可编辑文本输入。
因为我发现 WKInterfaceController 中的对象都不支持像 UITextfield 或 UITextview 一样的可编辑文本输入。
上面的答案没有代码,只有一个链接到苹果惊人的XD文档。 您可以使用以下代码(WatchOS2,iOS 9.2.1)启动具有一些语音选项的语音识别菜单:
//LAUNCH VOICE DICTATION (physical device only)
func launchVoiceDictationMenu(){
self.presentTextInputControllerWithSuggestions(["Hello","Goodbye","Hey"], allowedInputMode: WKTextInputMode.Plain,
completion:{(results) -> Void in
let aResult = results?[0] as? String
print(aResult)
})
}
使用Swift 3更新watchOS 3涂鸦模式
presentTextInputController(withSuggestions: ["watchOS3"], allowedInputMode: WKTextInputMode.plain) { (arr: [Any]?) in
print(arr ?? "Not find")
}
Swift 4
@IBAction func ReplyWithTextInputController(){
let phrases = ["OK", "I'm busy.", "Where are you?", "Thanks."]
presentTextInputController(withSuggestions: phrases,
allowedInputMode: WKTextInputMode.allowEmoji, completion: { (result) -> Void in
guard let choice = result else {
return
}
let suggestion = choice[0]
print(suggestion)
})
}