step—1:键盘的监听
1.一般在viewWillAppear:方法中添加监听事件
- (void)viewWillAppear:(BOOL)animated{
[superviewWillAppear:animated];
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotificationobject:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil];
}
//当键盘弹出时调用
- (void)keyboardWillShow:(NSNotification*)notification{
//获取键盘的高度
NSDictionary*userInfo = [notification userInfo];
NSValue*value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRectkeyboardRect = [value CGRectValue];
CGFloatheight = keyboardRect.size.height;
//第一种 self.view 平移的属性
//self.view.transform=CGAffineTr