<pre name="code" class="objc"><pre name="code" class="objc">#pragma mark view将要显示时
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//注册监听键盘显隐通知
//键盘出现时
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShow:) name:UIKeyboardDidShowNotification object:nil];
//键盘隐藏时
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBaHidden:) name:UIKeyboardDidHideNotification object:nil];
//根据键盘高度 改变 输入框和表格 的位置
[self changeInputViewTableViewPlaceWith:self.currentKeyboardHeight];
} #pragma mark 键盘显示时
- (void)keyboardWasShow:(NSNotification *)notification {
NSDictionary *info = [notification userInfo];
//获得键盘尺寸
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    //doing something
self.editHeight = keyboardSize.height; //重置当前键盘高度
//根据键盘高度 改变 输入框和表格 的位置
[self changeInputViewTableViewPlaceWith:self.editHeight];
} #pragma mark 键盘隐藏时
- (void)keyboardWillBaHidden:(NSNotification *)notification {
<pre name="code" class="objc">    //doing something

}#pragma mark 根据键盘高度 改变 输入框和表格 的位置- (void)changeInputViewTableViewPlaceWith:(CGFloat)height { [self.inputView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.bottom.equalTo(self.view).offset(-height); make.height.mas_equalTo(kInputHeight); }]; [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(64); make.width.equalTo(self.view); make.bottom.equalTo(self.inputView.mas_top); //使tableView滑到最下端 NSInteger arrCount = self.messagesArray.count; NSIndexPath *index = [NSIndexPath indexPathForRow:arrCount - 1 inSection:0]; if (arrCount > 0) { [self.tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionBottom animated:YES]; } if (height > kMoreHeight) { CGFloat showhHeight = kHeight - kInputHeight - height - 64; CGFloat allHeight = self.tableView.contentSize.height; CGPoint contentPoint = CGPointMake(0, allHeight - showhHeight); [self.tableView setContentOffset:contentPoint animated:YES]; } }];}



												

iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移的更多相关文章

  1. EditText获取和失去焦点,软键盘的关闭,和软键盘的显示和隐藏的监听

    软键盘显示和隐藏的监听: 注: mReplayRelativeLayout是EditText的父布局 //监听软键盘是否显示或隐藏 mReplayRelativeLayout.getViewTreeO ...

  2. Android 软键盘的显示和隐藏,这样操作就对了

    一.前言 如果有需要用到输入的地方,通常会有需要自动弹出或者收起软键盘的需求.开篇明义,本文会讲讲弹出和收起软键盘的一些细节,最终还会从源码进行分析. 想要操作软键盘,需要使用到 InputMetho ...

  3. android 软键盘的显示与隐藏问题的研究

    在android中,常常会和输入法的软件键盘交互.在Manifest文件中,系统给activity的一个属性-windowSoftInputMode来控制输入法的显示方式. 该属性提供了Activit ...

  4. 日积月累:EditText软键盘的显示和隐藏

    在工作过程中,常常会遇见需要根据自己的需求,控制文本框的键盘显示和隐藏. 通过查阅Android文档,介绍可以通过在清单文件中<activity>元素中添加android:windowSo ...

  5. IOS swift实现密码的显示与隐藏切换

    最近做项目遇到一个需要做密码的显示与隐藏功能,简单从功能上讲是比较简单的,但是,ios有个恶心的BUG,就是在切换显示密码后再隐藏密码时输入就被清空了,这个非常不友好,为了解决这个问题,我在网上找了相 ...

  6. Android基础-EditText键盘的显示与隐藏

    场景一.点击EditText之外的空白区域隐藏键盘: how to hide soft keyboard on android after clicking outside EditText? 首先定 ...

  7. android软键盘的显示和隐藏

    显示: InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.toggle ...

  8. iOS中监控软键盘显示或隐藏的可靠方法

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 如果你试图在软键盘的显示或隐藏时去改变的UI界面结构,仅有的方 ...

  9. IOS 键盘的显示与关闭

    在每一个IOS应用中,几乎不可避免的要进行文本输入操作,例如要求用户填写登陆注册信息,进行话题的评论回复,等等.用到的文本输入组件有UITextField,UITextView,对于这两个组件的相关属 ...

随机推荐

  1. WPF 保存image控件里的图片

    string ProImgPath = ProcessPath + name + ".png";//要保存的图片的地址,包含文件名 BitmapSource BS = (Bitma ...

  2. java笔试题

    下面有关JVM内存,说法错误的是? A.程序计数器是一个比较小的内存区域,用于指示当前线程所执行的字节码执行到了第几行,是线程隔离的 B.Java方法执行内存模型,用于存储局部变量,操作数栈,动态链接 ...

  3. 本地maven仓库使用及配置

    本地仓库的创建 下载 nexus-2.11.4-01-bundle.zip 解压并运行C:\nexus-2.11.4-01-bundle\nexus-2.11.4-01\bin\jsw\windows ...

  4. PHP程序员如何理解IoC/DI

    思想是解决问题的根本 思想必须转换成习惯构建一套完整的思想体系是开发能力成熟的标志 详情请点击

  5. 【LeetCode】Palindrome Pairs(336)

    1. Description Given a list of unique words. Find all pairs of distinct indices (i, j) in the given ...

  6. URL的组成格式

    最近在学习js的Ajax方面的内容,发现自己对基础的计算机网络知识认识不足,所以大概了解了下. URL组成格式 图中中括号是可选项 protocol 协议,常用的协议是http hostname 主机 ...

  7. Circuit Breaker Pattern(断路器模式)

    Handle faults that may take a variable amount of time to rectify when connecting to a remote service ...

  8. ADO.net 更新和插入数据 遇到null 执行不成功

    首先交代下背景,遇到一个问题:SqlCommand新增记录时,参数为null时,运行并不报错,只是返回(0),也就是更新失败. 在用C#往数据库里面插入记录的时候, 可能有的字段我们并不赋值(有可能是 ...

  9. BizTalk Server 2016

    10月28日微软正式发布BizTalk第十个版本BizTalk Server 2016,陆续发布了Azure VM镜像.MSDN版本.开发者版本等.以下为BizTalk Server 2016 新特性 ...

  10. 【转】单例模式(Singleton)

    首先来明确一个问题,那就是在某些情况下,有些对象,我们只需要一个就可以了, 比如,一台计算机上可以连好几个打印机,但是这个计算机上的打印程序只能有一个, 这里就可以通过单例模式来避免两个打印作业同时输 ...