iOS:如何检测键盘更改事件

编程入门 行业动态 更新时间:2024-10-27 11:25:04
本文介绍了iOS:如何检测键盘更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:35:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184020.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:键盘   事件   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!