2014-02-18 82 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