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
總結
以上是生活随笔為你收集整理的iphone开发:键盘事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拉线前要理线,综合布线的八点准备事项
- 下一篇: cad面积累计lisp怎么用_CAD里面