iphone开发:键盘事件
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
相关新闻>>
- 发表评论
-
- 最新评论 更多>>