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

    }


  • 相关阅读:
    正则表达式
    面向对象(访问控制、继承、重写)
    你凌晨1点半会想什么
    10、android学习资源整理
    9、android开发之java.lang.verifyError(转载)
    8、android代码优化技术记录
    6、android 普通日志输出到SD卡
    刷机总结(阿里云os-->android4.2.2)注明:本文不是教程
    忘记树莓派密码怎么办?
    7、android的button如何平铺一张图片?
  • 原文地址:https://www.cnblogs.com/eagley/p/1743492.html
Copyright © 2011-2022 走看看