//通知:注册键盘将要出现的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboadWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
ide
/**
* 键盘的处理
*/动画
//键盘出现时候调用的事件
-(void) keyboadWillShow:(NSNotification *)note{
//获取字典:
NSDictionary *infoDic = note.userInfo;
if (!_texField.isFirstResponder) return;
//键盘的frame:
CGSize keyboardSize = [[infoDic objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
//textF一下的高度高度
CGFloat offY = [UIScreen mainScreen].bounds.size.height-64-_bottomS.bottom-10;
NSLog(@"键盘的高度:%.02f ---_textField.height%f",keyboardSize.height,_bottomS.bottom-10);
NSLog(@"textF一下的高度高度:%.02f",offY);
if (offY < keyboardSize.height) {//键盘高度大于textFeild;
//添加动画效果:第一种:比较简单;都同样:
[UIView animateWithDuration:0.4 animations:^{
//直接往上移动控制器视图:
self.view.transform = CGAffineTransformMakeTranslation(0, -(keyboardSize.height-offY));
} completion:nil];
}else if (offY > keyboardSize.height){
}
}orm
//键盘消失时候调用的事件
-(void)keyboardWillHide:(NSNotification *)note{
self.view.transform = CGAffineTransformIdentity;
}
-(void)dealloc{
////移除观察者:方法一
[[NSNotificationCenter defaultCenter] removeObserver:self];
}server