2014-02-18 129 views
2

如何檢查iOS中的鍵盤是否顯示字典或單詞建議(我不知道正確的術語)。檢查iOS中是否存在單詞建議/詞典鍵盤

enter image description here

我搜索過網,但我沒有找到答案。 在這些詞後面的建議/字典是我的輸入字段,但是當這個詞建議/字典存在時,它被隱藏在它後面。我希望我的輸入可以將它動態地放在建議/詞典的頂部,只要它們在場。要做到這一點,我只需要一個通知,每當字建議/字典存在。有誰知道如何?

回答

1

我也不知道有什麼建議吧......一詞

但是你可以用NSNotificationCenter觀察鍵盤調整通知

試試吧。

也許幫助〜

- (void)viewDidLoad { 

    [super viewDidLoad]; 
    //add UIKeyboardWillShowNotification to NSNotificationCenter 
    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(keyboardShow:) 
              name:UIKeyboardWillShowNotification 
              object:nil]; 
} 

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

    //Should Log when keyboard show or resize   
    NSLog(@"keyboard notification"); 

    NSDictionary *userInfo = [notification userInfo]; 

    //Get the keyboard 
    NSValue *keyBoardValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; 

    //Get the keyboard Rect 
    CGRect keyboardRect = [keyBoardValue CGRectValue]; 

    NSLog(@"%@",[NSValue valueWithCGRect:keyboardRect]); 
} 

然後,當你操作鍵盤

你應該是這個樣子......

keyboard notification 
NSRect: {{0, 228}, {320, 252}} 
keyboard notification 
NSRect: {{0, 264}, {320, 216}} 
keyboard notification 
NSRect: {{0, 228}, {320, 252}} 
keyboard notification 
NSRect: {{0, 264}, {320, 216}} 
keyboard notification 
NSRect: {{0, 228}, {320, 252}} 
1

添加觀察員UIKeyboardDidChangeFrameNotification



[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil]; 

在keyboardDidChangeFrame檢索UIKeyboardFrameEndUserInfoKey的值,如果提出的建議,你會得到高度的258,其他225



- (void)keyboardDidChangeFrame:(NSNotification*)notification{ 
    NSDictionary *keyboardInfo = [notification userInfo]; 
    CGRect keyboardFrame = [[keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    CGFloat keyboardHeight = CGRectGetHeight(keyboardFrame); 
    NSLog(@"%f", keyboardHeight); 
} 

+0

完美解決方案。但是這會給幀後有鍵盤「UIKeyboardWillChangeFrameNotification」使用此之前,對於當前鍵盤的偉大工程。 – TamilKing