zoukankan      html  css  js  c++  java
  • [ios] 适应键盘高度变化

      1. - (void)regNotification  
      2. {  
      3.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];  
      4. }  
      5.   
      6. - (void)unregNotification  
      7. {  
      8.     [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];  
      9. }  
      10.   
      11. #pragma mark - notification handler  
      12.   
      13. - (void)keyboardWillChangeFrame:(NSNotification *)notification  
      14. {  
      15.     NSDictionary *info = [notification userInfo];  
      16.     CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];  
      17.     CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];  
      18.     CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];  
      19.       
      20.     CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;  
      21.       
      22.     CGRect inputFieldRect = self.inputTextField.frame;  
      23.     CGRect moreBtnRect = self.moreInputTypeBtn.frame;  
      24.       
      25.     inputFieldRect.origin.y += yOffset;  
      26.     moreBtnRect.origin.y += yOffset;  
      27.       
      28.     [UIView animateWithDuration:duration animations:^{  
      29.         self.inputTextField.frame = inputFieldRect;  
      30.         self.moreInputTypeBtn.frame = moreBtnRect;  
      31.     }];  

  • 相关阅读:
    线程间的通信
    高速排序算法
    LightOJ 1205 Palindromic Numbers
    java异常处理
    Android Bundle类
    Linux守护进程的编程实现
    深入浅出JMS(一)——JMS简单介绍
    Maven安装与配置
    matlab学习------------普通dialog对话框,错误对话框errordlg,警告对话框warndlg
    读书笔记:计算机网络4章:网络层
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/3043920.html
Copyright © 2011-2022 走看看