HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 不推荐使用UITextInputMode currentInputMode.建议更换?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在@R_618_9616@程序中,我们想要检测当前的键盘语言.例如,如果用户在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.建议更换?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。