解决iOS键盘输入中文后视图异常
来源:互联网 发布:网络舆情报告模板 编辑:程序博客网 时间:2024/05/01 19:54
1.在- (void)viewDidLoad中监听键盘高度的变换
2.键盘事件响应
//监听键盘高度的变换 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; // 键盘高度变化通知,ios5.0新增的#ifdef __IPHONE_5_0 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version >= 5.0) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillChangeFrameNotification object:nil]; }#endif
2.键盘事件响应
其中textInputView为输入框所在View,bubbleTable为消息显示View,480为textInputView与bubbleTable的原始高度之和
-(void) autoMovekeyBoard: (float) h{ textInputView.frame = CGRectMake(0.0f, (float)(480.0 - h - textInputView.frame.size.height), textInputView.frame.size.width, textInputView.frame.size.height); bubbleTable.frame = CGRectMake(0.0f, 0.0f, bubbleTable.frame.size.width, (float)(480.0 - h -textInputView.frame.size.height));}#pragma mark -#pragma mark Responding to keyboard events- (void)keyboardWillShow:(NSNotification *)notification { [bubbleTable scrollBubbleViewToBottomAnimated:YES];//键盘将要显示,滚动聊天视图到最底部 /* Reduce the size of the text view so that it's not obscured by the keyboard. Animate the resize so that it's in sync with the appearance of the keyboard. */ NSDictionary *userInfo = [notification userInfo]; // Get the origin of the keyboard when it's displayed. NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; // Get the top of the keyboard as the y coordinate of its origin in self's view's coordinate system. The bottom of the text view's frame should align with the top of the keyboard's final position. CGRect keyboardRect = [aValue CGRectValue]; // Get the duration of the animation. NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; // Animate the resize of the text view's frame in sync with the keyboard's appearance. [self autoMovekeyBoard:keyboardRect.size.height];}- (void)keyboardWillHide:(NSNotification *)notification { NSDictionary* userInfo = [notification userInfo]; /* Restore the size of the text view (fill self's view). Animate the resize so that it's in sync with the disappearance of the keyboard. */ NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]; NSTimeInterval animationDuration; [animationDurationValue getValue:&animationDuration]; [self autoMovekeyBoard:0];}
- 解决iOS键盘输入中文后视图异常
- iOS模拟器键盘输入中文解决方案
- 解决iOS打印数组和字典中文显示异常问题
- MyEclipse-->Servers视图异常解决
- iOS项目开发实战——制作视图的平移动画以及解决移动异常问题
- 解决 Cookie 中文存储异常
- Sqlci 解决插入中文异常
- iOS8 模拟器键盘输入中文
- iOS 11后滚动视图自适应 问题
- iOS-监听键盘输入,视图整体上移或恢复-避免输入遮挡
- iOS输入视图(如UITextView UITextField)点击时没有弹出键盘输入窗
- 关于JKAlertDialog在多个视图控制器跳转后不能正常显示的问题的解决--IOS
- Zbar IOS 解决中文乱码
- iOS 7 表视图顶部空白解决
- iOS 解决视图往下偏移的问题
- Eclipse 异常关闭后,无法启动解决
- tomcat部署项目启动后异常解决
- MultiDex后java.lang.NoClassDefFoundError异常解决
- iOS 中的Url 编码
- Fragment 多tab切换,顶部tab,顶部tab+viewpager
- #define总结 (网上资料汇集)
- APK手动签名 总结
- 重写Dialog写出自己的Dialog
- 解决iOS键盘输入中文后视图异常
- 用DDMS,查看进程/线程/内存/文件系统等
- HDU 1561(Tree Dp)
- 面向服务的体系结构(SOA) 云计算 数字化校园
- WebService之SOAP
- 将应用程序加到分享列表及如何使用
- rpm 安装jdk-6u45-linux-amd64.rpm发现需要依赖相关的库
- java awt 持有对方引用、内部类
- ramdisk.img及boot.img的生成过程