Keyboard autocorrection height (with/without the autocorrection)

断了今生、忘了曾经 提交于 2019-12-10 17:54:02

问题


I get the keyboard height like this:

- (void)keyboardNotification:(NSNotification*)notification
{
    NSDictionary* keyboardInfo = [notification userInfo];
    NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue];
}

Now, I have the keyboard height. But without the autocorrection height:

If the UITextAutocorrectionType is YES / NO the keyboard height stay the same.

How can I get the Keyboard autocorrection height?

Thanks in advance.


回答1:


Use this :

 CGRect keyboardBounds;
        [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue: &keyboardBounds];
   // Need to translate the bounds to account for rotation.
  keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];



回答2:


Use UIKeyboardWillChangeFrameNotification. This will be called every time when suggestion bar shows or hides.

NSConcreteNotification 0xc472900 {name = UIKeyboardWillChangeFrameNotification; userInfo = {
    UIKeyboardAnimationCurveUserInfoKey = 7;
    UIKeyboardAnimationDurationUserInfoKey = "0.25";
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 216}}";
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 588}";
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 372}";
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 480}, {320, 216}}";
    UIKeyboardFrameChangedByUserInteraction = 0;
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 264}, {320, 216}}";
}}


来源:https://stackoverflow.com/questions/30433653/keyboard-autocorrection-height-with-without-the-autocorrection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!