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 に答える