---
title: "iOS Keyboard 键盘高度变化 自适应"
author: "janedoneway"
date: "2013-01-15T15:43:03Z"
tags: []
categories: ["移动开发"]
slug: "ios-keyboard"
draft: false
lastmod: "2013-01-15T15:43:03Z"
id: 1770192
url: "https://janedoneway.iteye.com/blog/1770192"
---

\[\[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillShow:)

                                                 name:UIKeyboardWillShowNotification object:nil];

    

    \[\[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardDidShow:)

                                                 name:UIKeyboardDidShowNotification object:nil];

    

    

    

    \[\[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillHide:)

                                                 name:UIKeyboardWillHideNotification object:nil];

 

 

#pragma mark - 

 

\- (void)keyboardWillShow:(NSNotification\*)aNotification

{

    XuChiLog(@"%@", NSStringFromSelector(\_cmd));

    

    NSDictionary* info = \[aNotification userInfo];

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

    CGSize ekbSize = \[\[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    XuChiLog(@"beginkeyBoard Size: %@", NSStringFromCGSize(bkbSize));

    XuChiLog(@"  endkeyBoard Size: %@", NSStringFromCGSize(ekbSize));

}

 

\- (void)keyboardWillHide:(NSNotification\*)aNotification

{

    XuChiLog(@"%@", NSStringFromSelector(\_cmd));

    

    NSDictionary* info = \[aNotification userInfo];

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

    CGSize ekbSize = \[\[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    XuChiLog(@"beginkeyBoard Size: %@", NSStringFromCGSize(bkbSize));

    XuChiLog(@"  endkeyBoard Size: %@", NSStringFromCGSize(ekbSize));

}

 

\- (void)keyboardDidShow:(NSNotification\*)aNotification

{

    XuChiLog(@"%@", NSStringFromSelector(\_cmd));

    

    NSDictionary* info = \[aNotification userInfo];

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

    CGSize ekbSize = \[\[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    XuChiLog(@"beginkeyBoard Size: %@", NSStringFromCGSize(bkbSize));

    XuChiLog(@"  endkeyBoard Size: %@", NSStringFromCGSize(ekbSize));

}