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

  • 相关阅读:
    WC命令
    dcoker machine
    linux命令
    Valgrind 检测程序内存使用
    golang flag
    面试之---二叉树的遍历
    FFMpeg 版本错误
    C++中namespace的使用
    QT之QStatusBar
    建立ftp服务器和客户端
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/3043920.html
Copyright © 2011-2022 走看看