弹出键盘操作
//1.定制通知
//在初始化时定制通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
//2.对应的方法。
-(void)KeyboardWillShow:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
//获取高度
NSValue *value = [info objectForKey:@"UIKeyboardBoundsUserInfoKey"];//关键的一句,网上关于获取键盘高度的解决办法,多到这句就over了。系统宏定义的UIKeyboardBoundsUserInfoKey等测试都不能获取正确的值。不知道为什么。。。
CGSize keyboardSize = [value CGRectValue].size;
NSLog(@"横屏%f",keyboardSize.height);
float keyboardHeight = keyboardSize.height;
// 获取键盘弹出的时间
NSValue *animationDurationValue = [[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration;
[animationDurationValue getValue:&animationDuration];
//自定义的frame大小的改变的语句
//...
}