iphone开发:键盘事件

iphone开发:键盘事件

http://www.2cto.com/kf/201205/133800.html

   



       
UIKIT_EXTERN NSString *const UITextInputCurrentInputModeDidChangeNotification__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_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 //繁体笔画
通过LOG看到,我们当前只能拿到用户以何种语言输入。不过对于当前的大部分应用来说,这个已经足够了。
直接获取方式:
[[UITextInputMode currentInputMode] primaryLanguage];

 其实它返回的是个UIKeyboardInputMode类,这个是私有API 并不只有primaryLanguage这一个属性 看下面


@interface UIKeyboardInputMode : UITextInputMode
{
    NSString *primaryLanguage;
    NSString *identifier;
    NSString *softwareLayout;
    NSString *hardwareLayout;
}

+ (id)keyboardInputModeWithIdentifier:(id)arg1;
+ (id)hardwareLayoutFromIdentifier:(id)arg1;
+ (id)softwareLayoutFromIdentifier:(id)arg1;
+ (id)canonicalLanguageIdentifierFromIdentifier:(id)arg1;
@property(retain, nonatomic) NSString *hardwareLayout; // @synthesize hardwareLayout;
@property(retain, nonatomic) NSString *softwareLayout; // @synthesize softwareLayout;
@property(retain, nonatomic) NSString *identifier; // @synthesize identifier;
@property(retain, nonatomic) NSString *primaryLanguage; // @synthesize primaryLanguage;
- (void)dealloc;
- (id)initWithIdentifier:(id)arg1;

@end

就可以根据@property(retain, nonatomic) NSString *hardwareLayout; // @synthesize hardwareLayout;
@property(retain, nonatomic) NSString *softwareLayout; // @synthesize softwareLayout;
@property(retain, nonatomic) NSString *identifier; // @synthesize identifier;
@property(retain, nonatomic) NSString *primaryLanguage; // @synthesize primaryLanguage;
这几个属性判断

NSLog(@"%@",[(UIKeyboardInputMode*)[UITextInputMode currentInputMode] identifier]);
可以根据identifier判断,每种都不同的,你可以log出来看看

根据indentifier

    UITextInputMode* inputMode = [UITextInputMode currentInputMode];
    NSString* indentifier = [inputMode performSelector:NSSelectorFromString(@"identifier")];
    NSLog(@"%@",indentifier);
    //简体笔画 zh_Hans-Wubihua@sw=Wubihua;hw=US
    //简体手写 zh_Hans-HWR@sw=HWR
    //简体拼音 zh_Hans-Pinyin@sw=Pinyin;hw=US
    //英语 en_US@hw=US;sw=QWERTY

 


摘自 云怀空-abel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值