知道什么时候听写已经在UITextView中结束
我想知道什么时候听写已经结束了(理想情况是什么时候开始)。
包含UITextView
UIViewController
符合UITextInputDelegate
协议。
为了使它工作,我不得不订阅UITextInputCurrentInputModeDidChangeNotification
override func viewDidLoad() { super.viewDidLoad() NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil) }
并在那里添加委托(它没有工作,只是将其添加到viewDidLoad())
func changeInputMode(sender : NSNotification) { textView.inputDelegate = self }
开始和停止听写UITextInput现在正确调用所需的委托方法:
func selectionWillChange(textInput: UITextInput){ } func selectionDidChange(textInput: UITextInput){ } func textWillChange(textInput: UITextInput){ } func textDidChange(textInput: UITextInput){ }
但是没有被调用的是
func dictationRecordingDidEnd() { println("UITextInput Dictation ended") }
为什么? 我怎样才能得到通知/调用听写方法已经结束?
好吧,这是什么为我工作,而不是使用UITextInput
协议,但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 } } }