iOS 评论界面 监听键盘高度 动态改变输入框位置
2015-01-24 11:46
387 查看
</pre><p></p><div></div><div><pre name="code" class="objc">#pragma mark - 监听键盘高度 -(void)viewWillAppear:(BOOL)animated { [self registerForKeyboardNotifications]; } -(void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)registerForKeyboardNotifications { //使用NSNotificationCenter 鍵盤出現時 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil]; //使用NSNotificationCenter 鍵盤隐藏時 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:)name:UIKeyboardWillHideNotification object:nil]; } //实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置 - (void)keyboardWasShown:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; //kbSize即為鍵盤尺寸 (有width, height) CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到鍵盤的高度 NSLog(@"hight_hitht:%f",kbSize.height); _keyboardhight = kbSize.height; //输入框位置动画加载 [self begainMoveUpAnimation:kbSize.height]; } //当键盘隐藏的时候 - (void)keyboardWillBeHidden:(NSNotification*)aNotification { //do something } -(void)begainMoveUpAnimation:(CGFloat)keyboardhight{ [UIView animateWithDuration:0.1 animations:^{ self.view.center = CGPointMake(WIDTH/2, HEIGHT/2 + 32 - keyboardhight); }]; } #pragma mark- textView Delegate //开始输入 改变View的高度 - (BOOL)textViewShouldBeginEditing:(UITextField *)textField { [self begainMoveUpAnimation:_keyboardhight]; return YES; } //输入结束时调用动画(把按键。背景。输入框都移下去) -(void)textViewDidEndEditing:(UITextView *)textView { //释放 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; }
}
相关文章推荐
- ios 动态监听键盘输入法和高度
- iOS输入框随着键盘高度改变
- iOS 输入框弹出键盘后改变tableView高度内容不被遮挡
- iOS动态获取键盘高度实现流畅的键盘输入框开发
- iOS 监听键盘弹出的高度,避免挡住界面
- 动态监听键盘高度调整文本输入框
- iOS开发之监听键盘高度的变化 分类: ios技术 2015-04-21 12:04 233人阅读 评论(0) 收藏
- iOS UITextField位置随输入键盘动态改变 点击背景键盘消失
- iOS中改变键盘的高度 监听键盘
- 文本框随键盘动态改变位置(获取键盘弹起高度)
- ios 动态监听键盘输入法和高度
- iOS 监听键盘高度,输入框上升
- ios 动态监听键盘输入法和高度
- iOS技巧——即时监听键盘高度
- iOS开发 改变UINavigationController的UINavigationBar的高度和背景图片 分类: ios技术 2015-04-16 15:49 233人阅读 评论(0) 收藏
- IOS简单实现输入框随着键盘的弹出动态上升(很简单的)
- ios 键盘高度改变通知
- 动态计算iOS键盘高度
- ios开发 监听键盘frame变化事件获取键盘高度( ios8&ios7 横竖屏旋转时需要注意的问题)
- iOS UITextField随着键盘的高度变化动态调整位置