美文网首页
获取键盘弹出或收回时frame

获取键盘弹出或收回时frame

作者: 又又轻 | 来源:发表于2016-11-04 10:13 被阅读35次

[[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

      本文链接:https://www.haomeiwen.com/subject/vttfdttx.html