ios 利用通知处理键盘的显示与隐藏
2014-09-15 20:08
411 查看
1.监听键盘通知
<
4000
span style="font-size:18px;">
- (void)viewDidLoad
{
[super
viewDidLoad];
// 监听键盘的通知
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}
当键盘改变了frame(位置和尺寸)的时候调用
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
// 设置窗口的颜色
self.view.window.backgroundColor =
self.tableView.backgroundColor;
// 0.取出键盘动画的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
// 1.取得键盘最后的frame
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey]
CGRectValue];
// 2.计算控制器的view需要平移的距离
CGFloat transformY = keyboardFrame.origin.y -
self.view.frame.size.height;
// 3.执行动画
[UIView animateWithDuration:duration
animations:^{
self.view.transform =
CGAffineTransformMakeTranslation(0, transformY);
}];
}
2.当开始拖拽表格的时候调用(隐藏键盘)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
// 退出键盘
[self.view
endEditing:YES];
}
3.注销监听器
- (void)dealloc
{
[[NSNotificationCenter
defaultCenter] removeObserver:self];
}
<
4000
span style="font-size:18px;">
- (void)viewDidLoad
{
[super
viewDidLoad];
// 监听键盘的通知
[[NSNotificationCenter
defaultCenter] addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
}
当键盘改变了frame(位置和尺寸)的时候调用
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
// 设置窗口的颜色
self.view.window.backgroundColor =
self.tableView.backgroundColor;
// 0.取出键盘动画的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
// 1.取得键盘最后的frame
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey]
CGRectValue];
// 2.计算控制器的view需要平移的距离
CGFloat transformY = keyboardFrame.origin.y -
self.view.frame.size.height;
// 3.执行动画
[UIView animateWithDuration:duration
animations:^{
self.view.transform =
CGAffineTransformMakeTranslation(0, transformY);
}];
}
2.当开始拖拽表格的时候调用(隐藏键盘)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
// 退出键盘
[self.view
endEditing:YES];
}
3.注销监听器
- (void)dealloc
{
[[NSNotificationCenter
defaultCenter] removeObserver:self];
}
相关文章推荐
- iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项
- iOS 键盘处理(改变键盘为完成键),UITextField键盘显示隐藏,弹出,回弹
- ios之让输入键盘隐藏消失的方法/以及系统通知的实现
- iOS开发中的键盘显示和隐藏
- 处理iOS键盘通知
- [iOS]利用通知实现监听系统键盘
- 定制scrollView来处理自动显示与隐藏键盘
- IOS 键盘的显示与关闭,以及移动显示(UITextView处理完整版)(完美中文键盘输入避免触摸无效,做双重保障)
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- 监听键盘的显示和隐藏 通知
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- (素材源码)猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- (素材源码)猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复
- 利用状态模式处理多个模态弹出层的显示隐藏
- QQ聊天布局——利用通知机制实现键盘处理
- iOS开发 键盘处理 (隐藏,自动转到下个文本框,轻触背景隐藏)
- iOS中监控软键盘显示或隐藏的可靠方法
- iOS中监控软键盘显示或隐藏的可靠方法
- AJ学IOS(18)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复