0

私のアプリケーションでは、とを使用しUIScrollViewています。UITextField でキーボードの向きのコーディングを行いました。正常に動作していますが、動作していません。で編集している間、キーボードは. これが私のコードですUITextFieldUITextViewUITextViewUITextViewUITextView

- (void)textFieldDidBeginEditing:(UITextField *)textField {
  [textField setClearButtonMode:UITextFieldViewModeWhileEditing];
  CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
  CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
  CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
  CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
  CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
  CGFloat heightFraction = numerator / denominator;
  if (heightFraction < 0.0) {
    heightFraction = 0.0;
  } else if (heightFraction > 1.0) {
    heightFraction = 1.0;
  }
  UIInterfaceOrientation orientation =
    [[UIApplication sharedApplication] statusBarOrientation];
  if (orientation == UIInterfaceOrientationPortrait ||
    orientation == UIInterfaceOrientationPortraitUpsideDown) {
    animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
  } else {
    animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
  }
  CGRect viewFrame = self.view.frame;
  viewFrame.origin.y -= animatedDistance;
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationBeginsFromCurrentState:YES];
  [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
  [self.view setFrame:viewFrame];
  [UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
  CGRect viewFrame = self.view.frame;
  viewFrame.origin.y += animatedDistance;
  [UIView beginAnimations:nil context:NULL];
  [UIView setAnimationBeginsFromCurrentState:YES];
  [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
  [self.view setFrame:viewFrame];
  [UIView commitAnimations];    
}

これをクリアするのを手伝ってくれる人はいますか?

4

3 に答える 3

1

以下のように UITextview の textview のデリゲート メソッドを使用します。

-(void)textViewDidBeginEditing:(UITextView *)textView;

そしてまた

-(void)textViewDidEndEditing:(UITextView *)textView;

textFieldデリゲートメソッドと同じ

例えば ​​...

-(void)textViewDidBeginEditing:(UITextView *)textView{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    self.view.frame=CGRectMake(0, -100, 320, 460);//just for an example
    [UIView commitAnimations];

}

-(void)textViewDidEndEditing:(UITextView *)textView{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    self.view.frame=CGRectMake(0,0, 320, 460);
    [UIView commitAnimations];
}

これがあなたを助けることを願っています..

:)

于 2012-09-14T11:32:11.753 に答える
0

最初に「.h」ファイルに追加します

負荷をかけた

textView.delegate=self;

次に、textViewのコードを指定します

textView.userinteractionEnabled=YES;
于 2012-09-14T12:00:36.980 に答える
0

TPKeyboardAvoidingから入手できる、強く推奨される「TPKeyboardAvoidingScrollView」を試すことができます。

于 2012-09-14T11:30:50.663 に答える