zoukankan      html  css  js  c++  java
  • 显示keyboard及输入框上移

    #pragma mark -

    #pragma mark Keyboard notifications from Apple's UICatalog example

    //The code comes straight from Apple's UICatalog example, except that I have modified the UI manipulation

    //to use bounds instead of frame, so that when keyboard is shown, the view "scrolls" to the right place

    //so that the input field would remain visible.

    - (void)keyboardWillShow:(NSNotification *)aNotification {

      // the keyboard is showing so resize the my height

      CGRect keyboardRect = [[[aNotification userInfoobjectForKey:UIKeyboardBoundsUserInfoKeyCGRectValue];

      NSTimeInterval animationDuration = [[[aNotification userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey]                            doubleValue];

     

      CGRect bounds = self.view.bounds;

      bounds.origin.y += keyboardRect.size.height;

     

      [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

      [UIView setAnimationDuration:animationDuration];

       self.view.bounds = bounds;

      [UIView commitAnimations];

    }

     

    - (void)keyboardWillHide:(NSNotification *)aNotification {

      // the keyboard is hiding reset the table's height

       CGRect keyboardRect = [[[aNotification userInfoobjectForKey:UIKeyboardBoundsUserInfoKeyCGRectValue];

      NSTimeInterval animationDuration = [[[aNotification userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey]                            doubleValue];

       CGRect bounds = self.view.bounds;

       bounds.origin.y -= keyboardRect.size.height;

     

      [UIView beginAnimations:@"ResizeForKeyboard" context:nil];

      [UIView setAnimationDuration:animationDuration];

      self.view.bounds = bounds;

      [UIView commitAnimations];

    }


  • 相关阅读:
    JDK 9 发布仅数月,为何在生产环境中却频遭嫌弃?
    MyBatis 延迟加载,一级缓存,二级缓存设置
    mysql jdbc url
    idea中模块累积编写
    Idea中通过Git将代码同步到GitHub
    HomeBrew安装及使用
    (二)Java秒杀项目之实现登录功能
    (一)Java秒杀项目之项目环境搭建
    Spring实现构造注入
    Mybatis动态SQL之使用foreach完成复杂查询
  • 原文地址:https://www.cnblogs.com/eagley/p/1743492.html
Copyright © 2011-2022 走看看