iOS 7键盘预测

时间:2014-08-07 16:49:46

标签: ios internationalization keyboard uikeyboard chinese-locale

我们正在为iOS 7应用添加支持,以便为亚洲用户提供支持。但是,对于使用中文字符的键盘,在if的顶部有一个包含预测文本的滚动视图。一旦用户开始输入,键盘上方就会出现水平滚动视图,并且永远不会被解除。

有没有办法检测用户何时开启预测的iOS 7中文字母键盘?这样我们就可以将元素向上移动一点来补偿它。

2 个答案:

答案 0 :(得分:2)

// ViewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardFrameDidShow:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardFrameWillChange:)
                                             name:UIKeyboardWillChangeFrameNotification
                                           object:nil];

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

    CGRect keyboardFrame;
    [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGRect inputPanelFrame = self.inputPanel.frame;

     UIView *superView = [ self.inputPanel superview];

    inputPanelFrame.origin.y = (superView.frame.size.height -(keyboardFrame.size.height+self.inputPanel.frame.size.height));

    self.inputPanel.frame = inputPanelFrame;
}


- (void)keyboardFrameWillChange:(NSNotification *)notification
{
    CGRect keyboardFrame;
    [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGRect inputPanelFrame = self.inputPanel.frame;
      UIView *superView = [ self.inputPanel superview];
    inputPanelFrame.origin.y = (superView.frame.size.height -(keyboardFrame.size.height+self.inputPanel.frame.size.height));

    self.inputPanel.frame = inputPanelFrame;

}

答案 1 :(得分:1)

想出来!首先听听UIKeyboardWillChangeFrameNotification。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changed:) name:UIKeyboardWillChangeFrameNotification object:nil];

通知将发送包含许多键盘参数的字典。 UIKeyboardFrameEndUserInfoKey的高度将为您提供键盘高度的实时更新,包括来自亚洲键盘的预测。

- (void)changed:(NSNotification *)notification {
    NSDictionary *keyboardInfo = [notification userInfo];
    NSValue *keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
    float keyboardHeight = keyboardFrameBeginRect.size.height;
}