zoukankan      html  css  js  c++  java
  • UITextInputMode类的使用方法

    UITextInputMode大家看了是不是有些陌生呢?这个类是在4.2之后才有的一个新的类,是用来获取当前文本输入模式的。这个可能说的有些模糊。说白了就是在用户输入文本时,判断用户使用的是什么键盘的。

    其实用法很简单哦。

    如果要在用户改变输入方式时,获得此值,可如此使用:

    首先在用户开始输入之前注册通知:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeMode:) name:@"UITextInputCurrentInputModeDidChangeNotification" object:nil];

    然后实现上面的方法:

    -(void) changeMode:(NSNotification *)notification{

    NSLog(@"%@",[[UITextInputMode currentInputMode] primaryLanguage]);

    }

    这样就能拿到值了。

    下面是LOG结果:

    2011-07-18 14:32:48.565 UIFont[2447:207] zh-Hans //简体汉字拼音

    2011-07-18 14:32:50.784 UIFont[2447:207] en-US   //英文

    2011-07-18 14:32:51.344 UIFont[2447:207] zh-Hans //简体手写

    2011-07-18 14:32:51.807 UIFont[2447:207] zh-Hans //简体笔画

    2011-07-18 14:32:53.271 UIFont[2447:207] zh-Hant //繁体手写

    2011-07-18 14:32:54.062 UIFont[2447:207] zh-Hant //繁体仓颉

    2011-07-18 14:32:54.822 UIFont[2447:207] zh-Hant //繁体笔画

     

    - (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);

    }

  • 相关阅读:
    2020CCPC秦皇岛 K 【Kindom's Power】(树上贪心dp)
    对于树上状态机dp问题的一些总结与思考
    PTA_L3题解集
    PTA_L2题解集
    树上dp_学习笔记
    2020牛客国庆集训派对day2 B【Cheap Delivers】(最短路+状压dp)
    2020牛客国庆集训派对day1
    Codeforces 1426F【Number of Subsequences】(dp)
    2019icpc陕西省赛
    CF1281E【Jeremy Bearimy】(树上点对最大值/最小值和)
  • 原文地址:https://www.cnblogs.com/ChouDanDan/p/5051799.html
Copyright © 2011-2022 走看看