0

在我看来,我在滚动视图中有 14 个文本字段。

要在键盘出现/消失时向上/向下移动视图,我已经设置了滚动视图框架大小

#pragma mark - Text field view delegate methods
- (void)textFieldDidBeginEditing:(UITextField *)textField; 
{
      //To move the scroll view up to avoid keybord covers the text field
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDuration:0.3];
      [UIView setAnimationBeginsFromCurrentState:YES];
      //scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y - 45), scrollView.frame.size.width, scrollView.frame.size.height);


      [scrollView setContentSize:CGSizeMake(200, 1100)];

      [UIView commitAnimations];

}

- (void)textFieldDidEndEditing:(UITextField *)textField;       
{   
      //To move the view down 
      [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDuration:0.3];
      [UIView setAnimationBeginsFromCurrentState:YES];
       [scrollView setContentSize:CGSizeMake(200, 900)];
      //scrollView.frame = CGRectMake(scrollView.frame.origin.x, (scrollView.frame.origin.y + 45), scrollView.frame.size.width, scrollView.frame.size.height);
      [UIView commitAnimations];

}

返回键盘专注于下一个字段和最后一个字段键盘辞职

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{


      if(textField == nameField) {
            [emailText becomeFirstResponder];
      } else if(textField == emailText) {
            [mobileText becomeFirstResponder];
      }
      else if(textField == mobileText) {
            [iPhoneText becomeFirstResponder];
      }
      else if(textField == iPhoneText.value) {
            [companyText becomeFirstResponder];
      }
      else if(textField == companyText) {


       [roleText becomeFirstResponder];
  }

...
......
...........
  else if(textField == lastfield) { // Last fiels
        [textField resignFirstResponder];
  }





      return YES;
}

但我的意图是,当文本字段被聚焦时,文本字段会向上移动到键盘顶部或视图中心

怎么做

4

1 回答 1

1

我在我的应用程序中使用了 TPKeyboardAvoiding,它似乎对我来说非常有效,也许可以试一试。

于 2012-10-25T11:37:51.743 回答