键盘处理
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(add:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(down:) name:UIKeyboardWillHideNotification object:nil];
通知:
}
// 1. 上升
- (void)add:(NSNotification *)note
{
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
// 取出键盘的frame
NSValue *rectValue = note.userInfo[UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [rectValue CGRectValue];
// 2.2 让控制器的view 往上挪动一个键盘的高度
CGFloat ty = - keyboardRect.size.height; 负数表示上
self.view.transform = CGAffineTransformMakeTranslation(0, ty);
}];
}
// 2. 退回
- (void)down:(NSNotification *)note
{
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:duration animations:^{
// 清空transform 内容
self.view.transform = CGAffineTransformIdentity;
}];
}
iOS 中键盘上工具栏高度的变化
最新推荐文章于 2022-04-10 23:35:13 发布