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

  • 相关阅读:
    C# 深浅复制 MemberwiseClone
    负载均衡算法,轮询方式
    大话设计模式之工厂模式 C#
    大话设计模式:代理模式 C#
    C# 单元测试
    【前端安全】JavaScript防http劫持与XSS
    神秘的 shadow-dom 浅析
    【CSS进阶】伪元素的妙用2
    【CSS进阶】CSS 颜色体系详解
    【CSS进阶】box-shadow 与 filter:drop-shadow 详解及奇技淫巧
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/3043920.html
Copyright © 2011-2022 走看看