【发布时间】:2015-02-23 20:13:57
【问题描述】:
我已经找到了很多方法,但没有有效的解决方案。这是我尝试过但没有奏效的方法。
(1) 只需调用 primaryLanguage()
UITextInputMode().primaryLanguage
→ 总是返回 nil :-/
(2) 订阅UITextInputCurrentInputModeDidChangeNotification通知
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name: UITextInputCurrentInputModeDidChangeNotification, object: nil)
}
func changeInputMode(sender : NSNotification) {
...?!
}
通知正在被触发,但不清楚如何从通知中提取当前语言信息。
(3) 使用 activeInputModes()
let localeIdentifier = UITextInputMode.activeInputModes().first as? UITextInputMode
var locale:NSLocale = NSLocale(localeIdentifier: localeIdentifier.primaryLanguage!)
println("Input Mode Language \(localeIdentifier.primaryLanguage!)")
这总是提供所有可用键盘的相同数组,没有关于实际活动键盘的信息。
如何获取当前活动键盘的 NSLocale?
【问题讨论】:
标签: ios swift uitextinput