zoukankan      html  css  js  c++  java
  • iOS、Xcode监测键盘的显示和隐藏变化,并获得键盘高度,改变tableView的frame和偏移

    <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]; } }];}

    
    


    
    
    
    
  • 相关阅读:
    python2.7实现websocket服务器,可以在web实时显示远程服务器日志
    web请求的处理流程
    实现简单的django上传文件
    rsync+sersync实现数据文件实时同步
    WebSphere之wasprofile.sh使用
    WebSphere性能优化的几个方法
    WebSphere配置数据库连接池
    正则表达式(Regular Expression)
    FFT Golang 实现
    http://phantomjs.org/page-automation.html
  • 原文地址:https://www.cnblogs.com/moxiaoyan33/p/5309252.html
Copyright © 2011-2022 走看看