【问题标题】:Japanese keyboard's height日文键盘高度
【发布时间】:2012-06-26 14:42:19
【问题描述】:

我想向上滚动我的表单,让键盘在 UITextField 下。它适用于英文键盘,但是当我更改为日文键盘时,我的表格只能向上滚动一点。我调试了一下,发现两种情况下键盘的高度是不一样的。

我按照以下方式进行

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(keyboardWasShown:)
            name:UIKeyboardDidShowNotification object:nil];

   [[NSNotificationCenter defaultCenter] addObserver:self
             selector:@selector(keyboardWillBeHidden:)
             name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];

    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    NSLog(@"kbSize.height=%0.1f", kbSize.height);

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
    CGRect aRect = self.view.frame;
    aRect.size.height -= kbSize.height;
    if (!CGRectContainsPoint(aRect, activeField.frame.origin) )
    {
        CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
        [scrollView setContentOffset:scrollPoint animated:YES];
    }
}

- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    activeField = textField;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    activeField = nil;
}

这是信息的结果:

  1. 对于英文键盘:kbSize.height=216.0

  2. 对于日文键盘:kbSize.height=252.0

有人收到这个案子吗?有人可以帮我解决这个问题吗?

谢谢。

【问题讨论】:

    标签: iphone keyboard height


    【解决方案1】:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardModeChange:) name:UITextInputCurrentInputModeDidChangeNotification object:nil];
    

    【讨论】:

    • 您能否为您的回答提供更多背景信息?这可能有助于解释你在这里得到什么。
    猜你喜欢
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2016-10-21
    • 2015-05-06
    • 2015-03-05
    • 2015-11-14
    • 2017-02-10
    相关资源
    最近更新 更多