【问题标题】:iOS 7 Keyboard PredictionsiOS 7 键盘预测
【发布时间】:2014-10-01 00:25:47
【问题描述】:

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

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

【问题讨论】:

  • 只是想知道,但自动布局不应该解决这个问题吗?它可能是这种“底部栏下”行为的一部分,你也有标签栏。
  • 似乎没有帮助。

标签: ios internationalization keyboard uikeyboard chinese-locale


【解决方案1】:

//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;

}

【讨论】:

  • 您能否编辑您的答案以使代码格式正确? (使用页面底部的预览功能。)谢谢!
【解决方案2】:

想通了!首先监听 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;
}

【讨论】:

  • 对答案脱帽致敬
猜你喜欢
  • 2015-08-09
  • 1970-01-01
  • 2013-09-28
  • 2013-10-02
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多