gpt4 book ai didi

ios - 知道听写何时在 UITextView 中结束

转载 作者:搜寻专家 更新时间:2023-10-31 08:34:10 26 4
gpt4 key购买 nike

我想知道听写什么时候结束(最好是什么时候开始)。

我的 UIViewController 包含 UITextView 符合 UITextInputDelegate 协议(protocol)。

为了让它工作,我必须订阅 UITextInputCurrentInputModeDidChangeNotification

override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil)
}

并在此处添加委托(delegate)(仅将其添加到 viewDidLoad() 是行不通的)

func changeInputMode(sender : NSNotification) {
textView.inputDelegate = self
}

启动和停止听写 UITextInput 现在可以正确调用所需的委托(delegate)方法:

func selectionWillChange(textInput: UITextInput){    }
func selectionDidChange(textInput: UITextInput){ }
func textWillChange(textInput: UITextInput){ }
func textDidChange(textInput: UITextInput){ }

但是没有被调用的是

func dictationRecordingDidEnd() {
println("UITextInput Dictation ended")
}

为什么?如何在听写结束时收到通知/调用方法?

最佳答案

好的,这对我有用,不是使用 UITextInput 协议(protocol),而是使用 UITextInputCurrentInputModeDidChangeNotification

func changeInputMode(sender : NSNotification) {
var primaryLanguage = textView.textInputMode?.primaryLanguage

if primaryLanguage != nil {
var activeLocale:NSLocale = NSLocale(localeIdentifier: primaryLanguage!)
if primaryLanguage == "dictation" {
// dictation started
} else {
// dictation ended
}
}
}

关于ios - 知道听写何时在 UITextView 中结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com