zoukankan      html  css  js  c++  java
  • UITextField弹出键盘挡住输入框问题

    //开始编辑输入框的时候,软键盘出现,执行此事件

    -(void)textFieldDidBeginEditing:(UITextField *)textField

    {

        CGRect frame = [textField convertRect:textField.frame toView:self.view];

      //上移数值,根据自己情况调整

        int offset = frame.origin.y - 100 - (UISCROEEN_SIZE.height - 216.0);//键盘高度216

        

        NSTimeInterval animationDuration = 0.30f;

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

        [UIView setAnimationDuration:animationDuration];

        

        //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示

        if(offset > 0)

            self.view.frame = CGRectMake(0.0f, -offset, UISCROEEN_SIZE.width, UISCROEEN_SIZE.height);

        

        [UIView commitAnimations];

    }

    //输入框编辑完成以后,将视图恢复到原始状态

    -(void)textFieldDidEndEditing:(UITextField *)textField

    {

        self.view.frame = CGRectMake(0, 0, UISCROEEN_SIZE.width, UISCROEEN_SIZE.height);

    }

    - (BOOL)textFieldShouldReturn:(UITextField *)textField

    {

        [textField resignFirstResponder];

        return YES;

    }

  • 相关阅读:
    字典列表元组的推导式使用方法
    算法之排序
    闭包与装饰器
    循环(打印一些小东西)
    iOS内存小知识
    NSset
    字典
    NSNumber
    NSString
    NSArray
  • 原文地址:https://www.cnblogs.com/qianyindichang/p/3997853.html
Copyright © 2011-2022 走看看