2

ユーザーが編集を開始すると自動的にスクロールする必要がある UIScrollView 内に UITextView があります。これは、キーボードがテキストビューを覆うためです。

ここにコードがあります -

viewDidLoad:

feedBackformView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, segmentedControl.frame.origin.x + self.segmentedControl.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
feedBackformView.backgroundColor = [UIColor whiteColor];
feedBackformView.scrollEnabled = YES;
feedBackformView.delegate = self;
feedBackformView.userInteractionEnabled = YES;
feedBackformView.showsVerticalScrollIndicator = YES;
feedBackformView.contentSize = CGSizeMake(320, 700);

commentsView = [[UITextView alloc] initWithFrame:CGRectMake(5, emailField.frame.origin.y + 40, 250, 150)];
commentsView.delegate = self;
commentsView.layer.borderWidth = 2.0f;
commentsView.layer.cornerRadius = 5;

そしてここにデリゲートメソッドの実装があります -

-(void)textViewDidBeginEditing:(UITextView *)textView{
    CGPoint point = textView.frame.origin;
    [scrollView setContentOffset:point animated:YES];
}

しかし、何も起こりません。

4

3 に答える 3

4

あなたはうまくやっていますが、メソッドでコンテンツオフセットを設定している間、 scrollViewの代わりに feedBackformViewtextViewDidBeginEditing:を使用してください。以下のコードを見てください

feedBackformView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, 320, 200)];
feedBackformView.backgroundColor = [UIColor whiteColor];
feedBackformView.scrollEnabled = YES;
feedBackformView.delegate = self;
feedBackformView.userInteractionEnabled = YES;
feedBackformView.showsVerticalScrollIndicator = YES;
feedBackformView.contentSize = CGSizeMake(320, 700);

commentsView = [[UITextView alloc] initWithFrame:CGRectMake(5, 40, 250, 150)];
commentsView.delegate = self;
commentsView.layer.borderWidth = 2.0f;
commentsView.layer.cornerRadius = 5;

[feedBackformView addSubview:commentsView];
[self.view addSubview:feedBackformView];

テキストビューのDelegateMethodで、

-(void)textViewDidBeginEditing:(UITextView *)textView{
  CGPoint point = textView.frame.origin;
  [feedBackformView setContentOffset:point animated:YES];
 }

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

于 2013-04-18T04:49:58.543 に答える
1

スクロールのポイントはすでに目に見えるポイントにありますか?

-(void)textViewDidBeginEditing:(UITextView *)textView{
    // try this instead
    CGPoint point = CGPointMake(textView.frame.origin.x, 
                                textView.frame.origin.y + textView.frame.size.height);
    [scrollView setContentOffset:point animated:YES];

    // What does this produce?
    NSLog(@"%@ %@", NSStringFromCGPoint(scrollView.contentOffset),
                    NSStringFromCGRect(textView.frame));
}
于 2013-04-18T03:34:46.303 に答える
1

scrollViewscrollRectToVisible:animatedまたはsetContentOffset:animatedここで説明されているメソッドを使用できます: UIScrollView クラス リファレンス

UITextView には独自のスクロール ビューが付属していることに注意してください。そのため、別のスクロールビュー内にネストする必要がない場合があります。ただし、アプリがそれほど興味深い場合は、必要になる場合があります。

于 2013-04-18T03:22:16.923 に答える