【问题标题】:Scrolling to view textbox in UITableView footer滚动查看 UITableView 页脚中的文本框
【发布时间】:2011-08-10 04:27:54
【问题描述】:

我有一个文本框可以在 UITableView 页脚中输入代码。

当我点击文本框时,键盘会出现,但我不确定如何让 UITableView 滚动以使文本框可见

有任何代码示例吗?

【问题讨论】:

    标签: iphone uitableview scroll footer


    【解决方案1】:

    由于页脚无法向上滚动到 tableview 的最低点,您需要将 tableview 向上移动以显示文本框。

    这里有一篇不错的博文:http://cocoawithlove.com/2008/10/sliding-uitextfields-around-to-avoid.html

    【讨论】:

      【解决方案2】:

      从上一个 SO 问题中获得此代码。

       - (void)textFieldDidBeginEditing:(UITextField *)textField
          {
              if(textField == birthdayTextField)
                  [self animateTextField: textField up: YES];
          }
      
      
          - (void)textFieldDidEndEditing:(UITextField *)textField
          {
              if(textField == birthdayTextField)
                  [self animateTextField: textField up: NO];
          }
      
          - (void) animateTextField: (UITextField*) textField up: (BOOL) up
          {
              const int movementDistance = 80;  //change this around
              const float movementDuration = 0.3f; //change this around
      
              int movement = (up ? -movementDistance : movementDistance);
      
              [UIView beginAnimations: @"anim" context: nil];
              [UIView setAnimationBeginsFromCurrentState: YES];
              [UIView setAnimationDuration: movementDuration];
              self.view.frame = CGRectOffset(self.view.frame, 0, movement);
              [UIView commitAnimations];
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-22
        • 1970-01-01
        • 1970-01-01
        • 2015-08-20
        • 1970-01-01
        相关资源
        最近更新 更多