ios – 不推荐使用UITextInputMode currentInputMode.建议更换?

ios – 不推荐使用UITextInputMode currentInputMode.建议更换?,第1张

概述在我们的应用程序中,我们想要检测当前的键盘语言.例如,如果用户在Settings-> General-> Keyboard-> Keyboards下设置多个语言键盘,我们想知道他们输入的是哪种语言,并在此更改时从NSNotificationCenter获取通知. - (void)viewDidLoad{ [super viewDidLoad]; NSNotificationCen 在我们的应用程序中,我们想要检测当前的键盘语言.例如,如果用户在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.建议更换?全部内容,希望文章能够帮你解决ios – 不推荐使用UITextInputMode currentInputMode.建议更换?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1069551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存