- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我们的应用中,我们想要检测当前的键盘语言。例如,如果用户在 Settings->General->Keyboard->Keyboards 下设置了多语言键盘,我们想知道他们输入的是什么语言,并在更改时从 NSNotificationCenter 收到通知。
- (void)viewDidLoad
{
[super viewDidLoad];
NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter];
[nCenter addObserver:self selector:@selector(languageChanged:) name:UITextInputCurrentInputModeDidChangeNotification object:nil];
[self languageChanged:nil];
}
-(void)languageChanged:(NSNotification*)notification
{
for(UITextInputMode *mode in [UITextInputMode activeInputModes])
{
NSLog(@"Input mode: %@", mode);
NSLog(@"Input language: %@", mode.primaryLanguage);
}
NSLog(@"Notification: %@", notification);
UITextInputMode *current = [UITextInputMode currentInputMode];
NSLog(@"Current: %@", current.primaryLanguage);
}
我们通过这段代码发现,当用户使用键盘上的地球图标切换键盘时,通知会适本地触发,但是当我们迭代 UITextInputModes 时,它们以相同的顺序出现,没有(明显的)指示这是当前的,除非我们使用现已弃用的 [UITextInputMode currentInputMode]。
我找不到任何文档表明 Apple 建议替代此现已弃用的功能。有几个 SO 线程提到了弃用,但我没有找到解决方案。有任何想法吗?提前致谢。
最佳答案
通知 UITextInputCurrentInputModeDidChangeNotification 的对象是 UITextInputMode 的实例。
UITextInputMode *currentInputMode = [notification object];
此外,您还可以获得特定响应器上的事件输入模式:
UITextView *textView = [[UITextView alloc] init];
UITextInputMode *currentInputMode = textView.textInputMode;
目前在 iOS 7 上,表情符号键盘的 textInputMode/notification 对象为 nil。目前尚不清楚这是否是有意为之的行为。
关于ios - UITextInputMode currentInputMode 已弃用。建议更换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22614489/
我需要创建一个检测键盘输入语言的方法。例如,当键盘语言是法语时会做某事,而当英语是英语时会做其他事情 我在网上搜索找到了UITextInputMode但是我不知道怎么用,如果你能帮助我,我将不胜感激。
在我们的应用中,我们想要检测当前的键盘语言。例如,如果用户在 Settings->General->Keyboard->Keyboards 下设置了多语言键盘,我们想知道他们输入的是什么语言,并在更改
我一直在努力快速解决这个问题 iPhone: Change Keyboard language programmatically但我发现了一些我不知道如何解决的问题, 此方法使我的应用程序崩溃 UIT
我想在 Swift 2 中获取 UITextInputMode,但 UITextInputMode.activeInputModes() 崩溃了。 let x = UITextInputMod
我是一名优秀的程序员,十分优秀!