4

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

我的UIViewController其中包括UITextView符合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")
}

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

4

1 回答 1

4

好的,这对我有用的不是使用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
        }
    }
}
于 2015-02-28T08:53:27.020 回答