iOS技巧——即时监听键盘高度
来源:互联网 发布:windows arp a 编辑:程序博客网 时间:2024/05/17 08:04
需求:带输入框的view显示在界面最下端,当弹出键盘时,view要在键盘的上面,并且随着输入法的不同即时改变高度。
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view from its nib. //使用NSNotificationCenter 键盘出现时 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillAppear:) name:UIKeyboardDidShowNotification object:nil]; //使用NSNotificationCenter 键盘隐藏时 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil]; }实现方法
-(void)keyboardWillAppear:(NSNotification*)aNotification{ CGSize size = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; if (size.height == 216) { [UIView animateWithDuration:0.1 animations:^(void){ CGRect frame = _bottomView.frame; frame.origin.y = DeviceHeight - 216 -44; _bottomView.frame = frame; }]; }else{ [UIView animateWithDuration:0.1 animations:^(void){ CGRect frame = _bottomView.frame; frame.origin.y = DeviceHeight - 252 -44; _bottomView.frame = frame; }]; }}- (void)keyboardWillBeHidden:(NSNotification*)aNotification{ [UIView animateWithDuration:0.1 animations:^(void){ CGRect frame = _bottomView.frame; frame.origin.y = DeviceHeight -44; _bottomView.frame = frame; }];}其中 DeviceHeight 为设备高度的宏定义,用于 3.5、4寸屏幕的适配。
最后要在dealloc方法中移除通知
-(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];}
0 0
- iOS技巧——即时监听键盘高度
- ios键盘高度监听
- iOS 监听键盘高度,监听键盘出现 收回事件
- ios 动态监听键盘输入法和高度
- ios 动态监听键盘输入法和高度
- iOS 监听键盘的高度 - NSNotificationCenter
- cocos2dx-3.12 android/ios监听键盘高度
- ios 监听键盘弹起时间和高度
- iOS 键盘显示或消失的监听,获取键盘高度
- iOS监听键盘弹出,获取键盘的高度
- iOS笔记监听键盘状态 获取键盘高度
- iOS获取键盘弹出高度,监听键盘弹出退出
- iOS中改变键盘的高度 监听键盘
- iOS——获取键盘高度,
- iOS开发—获取系统键盘高度
- 监听键盘高度
- iOS开发之监听键盘高度的变化
- iOS开发之监听键盘高度的变化
- Sql Server中的NOLOCK作用
- Qt国际化(源码含中文时)的点滴分析
- 攀枝花电梯广告
- android expandable长按事件处理
- 防止网站进入沙盒的一些留神事变
- iOS技巧——即时监听键盘高度
- STL(4)之Removing Algorithms
- 代码中特殊的注释技术—TODO、FIXME和XXX的用处。
- vc下动态改变鼠标光标
- android中的数据库操作
- Tomcat的Manager显示403 Access Denied
- affine trans. 分析
- PD 脚本中列名注释用Name属性
- android http连接设置