iOS:如何检测键盘更改事件 [英] iOS: How to detect keyboard change event

查看:31
本文介绍了iOS:如何检测键盘更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 9.2、iOS 10.0+、swift4.

Xcode 9.2, iOS 10.0+ , swift4.

我正在开发一个项目,用户在 UITextField 中输入英文字符并将其转换为日语字符.它工作完美.现在,我想允许用户直接从日语键盘输入日语字符.在这种情况下,我想知道键盘已从默认更改为另一种类型/语言.

I'm working on a project where user inputs english characters in UITextField and it converted to Japanese language characters. and it is working perfect. now, i want to allow user to input Japanese language characters direct from Japanese Keyboard.In this situation i want to know that the keyboard is changed from default to another type/language.

那么,是否有任何可用的功能或通知可以帮助我?

So, is there any function or Notification is available that can help me?

推荐答案

您可以使用 UITextInputCurrentInputModeDidChange 通知来检测当前键盘语言何时更改.

You can use the UITextInputCurrentInputModeDidChange notification to detect when the current keyboard language changes.

NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: .UITextInputCurrentInputModeDidChange, object: nil)

@objc func inputModeDidChange(_ notification: Notification) {
    if let inputMode = notification.object as? UITextInputMode {
        if let lang = inputMode.primaryLanguage {
            // do something
        }
    }
}

这篇关于iOS:如何检测键盘更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆