你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iphone開發:鍵盤事件

iphone開發:鍵盤事件

編輯:IOS開發綜合



       
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

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved