如何获得iOS 8.3表情符号键盘高度? [英] How to get iOS 8.3 emoji keyboard height?

查看:127
本文介绍了如何获得iOS 8.3表情符号键盘高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以处理两个事件:键盘显示和键盘隐藏时。
在iOS 8.2及更早版本中,一切正常。

I can handle two events: when keyboard shows and when keyboard hides. Everything worked fine in iOS 8.2 and older.

但是如何在更改键盘语言时处理事件?当您将英文键盘更改为表情符号键盘时,表情符号键盘的高度(在ios 8.3中)更大并且隐藏了内容。

But how to handle event when you change your keyboard language? When you change the english keyboard to the emoji keyboard, the height of emoji keyboard (in ios 8.3) is bigger and it hides the content.

或许您有一个解决方案如何控制iOS 8.3表情符号键盘高度?

Or maybe you have a solution how to control iOS 8.3 emoji keyboard height?

推荐答案

好的。所以看着我的旧代码,我记得,我使用2个观察者( UIKeyboardDidShowNotification / UIKeyboardDidHideNotification )。我使用了一个观察者( UIKeyboardWillChangeFrameNotification ),触发了每个事件:键盘隐藏,键盘显示,键盘更换框架。

OK. So looking at my old code, I remembered, I do not use 2 observers (UIKeyboardDidShowNotification/UIKeyboardDidHideNotification). I use a single observer (UIKeyboardWillChangeFrameNotification), that is fired of each event: Keyboard hiding, keyboard showing, keyboard changing frame.

在我的例子中,文本框和发送按钮嵌套在 UIView 中,这是视图添加在视图中 UIViewController ,高于一切。

In my case, the text box and send button are in nested in a UIView and this is view is added in the view of the UIViewController, above everything else.

我在<$ c $中添加观察者c> viewDidAppear 并删除 viewWillDisappear 中的观察者。(以避免在视图未激活时触发任何通知)。

I add the observer in viewDidAppear and remove the observer in viewWillDisappear.(to avoid any notification firing when view is not active).

上述信息对于您的案例不是必需的,只是为了提供信息而添加它。相关代码如下:

The above information is not necessary for your case, just added it for information sake. Relevant code is as follows:

ADD OBSERVER:

- (void) viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

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

处理通知:

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

    NSDictionary* notificationInfo = [notification userInfo];

    CGRect keyboardFrame = [[notificationInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

    [UIView animateWithDuration:[[notificationInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]
                          delay:0
                        options:[[notificationInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue]
                     animations:^{

                         CGRect frame = self.textViewContainer.frame;
                         frame.origin.y = keyboardFrame.origin.y - frame.size.height;
                         self.textViewContainer.frame = frame;

                     } completion:nil];
}

您可能需要对进行一些调整frame.origin.y ... 正确计算的行。我不知道你是否有 UITabBarController 或底部的任何条形图。这里最安全的赌注是:

You might have to make a few adjustments to the frame.origin.y... line for correct calculations. I don't know whether you have a UITabBarController or any bars at the bottom. The safest bet here would be:

frame.origin.y = self.view.frame.size.height - keyboardFrame.size.height - X;

如果您的VC涵盖, X 为0整个屏幕。如果没有,请使用任何底栏的高度。

Where X is 0 if your VC covers the whole screen. If not, use the heights of any bottom bars.

这篇关于如何获得iOS 8.3表情符号键盘高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆