[英]Know when dictation has ended in a 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
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.