获取键盘弹出或收回时frame

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardWillChangeFrameNotification object:nil];



//实现接收到通知时的操作

-(void) keyBoardChange:(NSNotification *)note

{

//获取键盘弹出或收回时frame

CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

//获取键盘弹出所需时长

float duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];

//添加弹出动画

[UIView animateWithDuration:duration animations:^{

self.tableView.transform = CGAffineTransformMakeTranslation(0, keyboardFrame.origin.y - (mainHeight));

}];

}

你可能感兴趣的:(获取键盘弹出或收回时frame)