UIKeyboard建议iOS 8通知的高度?

Ton*_*riz 6 uikeyboard nsnotificationcenter ios ios8

我试图在iOS 8中保持一个文本字段位于键盘顶部.但是当用户向上或向下滑动键盘顶部以显示或消除iOS 8字建议时,我需要通知新的高度键盘,所以我可以向上或向下移动文本字段的高度.

我怎么能做到这一点?

谢谢!

cha*_*oad 10

您可以注册UIKeyboardDidShowNotification,然后通过UIKeyboardFrameEndUserInfoKey从通知中获取键盘框架.

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(handleKeyboardDidShowNotification:) 
                                             name:UIKeyboardDidShowNotification 
                                           object:nil];


- (void)handleKeyboardDidShowNotification:(NSNotification *)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    // Move your textview into view here
}
Run Code Online (Sandbox Code Playgroud)

即使键盘已经显示并且只是要改变大小,也会发送此通知,因此无论何时在键盘顶部向上或向下滑动,您都会收到该通知.