7
我有一个用户界面,当显示键盘时需要调整位置。iOS8 UIKeyboardWillShowNotification第三方键盘高度
以下是用来检测时,会显示一个键盘:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
注:我已经试过两UIKeyboardWillShowNotification和UIKeyboardDidShowNotification
- (void)keyboardWillShow:(NSNotification *)n {
if (isKeyboardShowing)
return;
NSDictionary* userInfo = [n userInfo];
// get the size of the keyboard
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
// Animate keyboard shift
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.2f animations:^{
// some animation here
} completion:^(BOOL finished) {
if (finished)
isKeyboardShowing = YES;
}];
对于自定义键盘上键盘尺寸返回{320 ,0}。由于键盘现在可以有不同的高度,因此当键盘出现时,我无法使用静态值来更改UI。
这是ios8的问题吗?有没有其他方法来动态获得键盘高度?
编辑:这是用户信息词典:
{name = UIKeyboardDidShowNotification; userInfo = {
UIKeyboardAnimationCurveUserInfoKey = 7;
UIKeyboardAnimationDurationUserInfoKey = "0.25";
UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}";
UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}";
UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}";
}}
在此先感谢。