iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
来源:互联网 发布:淘宝卖家骗局大全 编辑:程序博客网 时间:2024/05/19 17:48
<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]; } }];}
0 0
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- 显示或隐藏键盘改变tableView高度
- 显示或隐藏键盘改变tableView高度
- iOS开发监听键盘(添加键盘和隐藏键盘,改变视图中整体控件随着键盘的高度移动)
- uitableview 内的 uitextField 获得焦点后,显示键盘和table的frame变化,使uitextField不被遮挡
- 键盘的显示和隐藏
- iOS-OC-监听键盘的高度 隐藏和出现
- iOS获取键盘的高度(在键盘出现,改变和消失时通知改变)
- iOS 中获得键盘的弹出和隐藏
- 适应ios中键盘高度的变化
- iPhone获取键盘高度,通知方式隐藏和显示键盘
- 隐藏键盘和显示键盘
- 笔记--键盘的显示和隐藏
- iphone中键盘的显示和隐藏
- Android监听键盘的显示和隐藏
- Android 输入法键盘的隐藏和显示
- 监听键盘的显示和隐藏 通知
- 键盘隐藏和显示的方法
- [理解leetcode解法]176. Second Highest Salary
- 设计模式 ( 十二 ) 职责链模式(Chain of Responsibility)(对象行为)
- apprtc(webrtc) 本地搭建服务器
- 基于Redis实现分布式锁
- Android中shape中的属性大全
- iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移
- postgresql 9.3.1 编译安装
- centos网络配置实例
- C++第一次作业
- [LeetCode]221. Maximal Square
- 关于内存数据与 JSON
- c++第一次实验
- 谈谈如何在面试中发掘程序猿的核心竞争力zz
- Cygwin中vi编辑器方向键和Backspace键不好使的解决方法