完美解决ios4与ios5输入框随键盘移动问题
来源:互联网 发布:qq飞车星河战警数据 编辑:程序博客网 时间:2024/05/21 17:44
iOS5中当键盘输入法切换到中文时,键盘高度由216增加到252像素。这一变化将遮住输入框。如何才能解决这一问题呢?
在iOS5中,新增有notification(UIKeyboardWillChangeFrameNotification)可以用来监测键盘frame的变化。在iOS4中,可以通过UIKeyboardWillShowNotification以及UIKeyboardWillHideNotification来监测键盘的显示与隐藏事件。综合处理下,可以用以下方法解决:
- #ifndef IOS_VERSION
- #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
- #endif
在viewdidload中注册监测事件:
- if (IOS_VERSION < 5.0) {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillHideNotification object:nil];
- }else{
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- }
在dealloc中移除监测事件:
- if (IOS_VERSION < 5.0) {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }else{
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
- }
事件处理函数:
- - (void)keyboardWillChangeFrame:(NSNotification *)notification{
- if(!isDisplayFaceBox){
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- #endif
- #if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
- NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
- #else
- NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
- #endif
- CGRect keyboardBounds;
- [keyboardBoundsValue getValue:&keyboardBounds];
- //UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0);
- //[keyboardScrollView setScrollIndicatorInsets:e];
- //[keyboardScrollView setContentInset:e];
- NSInteger offset = 480-keyboardBounds.origin.y;
- CGRect listFrame = CGRectMake(0, offset, 320, 377-offset);
- [UIView beginAnimations:@"anim" context:NULL];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationBeginsFromCurrentState:YES];
- [UIView setAnimationDuration:0.3];
- //处理移动事件,将各视图设置最终要达到的状态
- [tableviewbo setFrame:listFrame];
- faceButton.hidden = NO;
- keyboardButton.hidden = YES;
- [keyboardScrollView setContentOffset:CGPointMake(0, offset) animated:NO];
- [self scrollToBottomAnimated:NO];
- [UIView commitAnimations];
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
- }
- #endif
- }
- }
- 完美解决ios4与ios5输入框随键盘移动问题
- 完美解决ios4与ios5输入框随键盘移动问题
- 完美解决ios4与ios5输入框随键盘移动问题
- IOS4与IOS5输入框随键盘移动问题
- 简单完美的解决键盘遮挡输入框的问题
- android,键盘遮挡了输入框,完美解决android键盘遮挡问题
- 移动端 ios键盘挡住底部 输入框的问题完美解决方案
- iOS5 切换中文键盘时覆盖输入框的完美解决方案
- iOS5网页视图(UIWebView)中的输入框不能弹出键盘的问题
- 解决键盘挡住输入框的问题
- 如何解决键盘遮挡输入框问题
- 解决键盘遮挡输入框问题
- iOS解决键盘遮挡输入框问题
- 输入框随键盘移动的实现
- swift 输入框随键盘移动
- 移动端输入框与底部定位键出现的键盘弹出问题
- 解决移动端虚拟键盘与fixed定位失效问题!
- android 键盘与输入框问题
- html页面自动刷新
- Linux 地址映射全过程(分段机制过程在Linux中不起作用)
- JS判断是否360浏览器代码
- 解放军美女网络尖兵,90余昼夜写代码40多万行
- 中央气象局天气预报城市对应的编码(到县为止)
- 完美解决ios4与ios5输入框随键盘移动问题
- 关于sizeof的几个问题
- Android自定义控件的属性
- SQLServer中SYSCOLUMNS表的各个字段的意义
- 程序猿的九重天
- 面试训练八皇后问题
- 淡墨写韵,不守起承转合
- share
- 饭工和碗工