4

I am using a scroll view that contains a couple of text field. When the text field "begins editing", I perform 3 operations:

  1. I change the scroll view content inset (so that the whole view becomes apparent above the keyboard). I only do that if it's not fixed already to this content inset.

  2. I also change the scroll indicator inset to match the one in 1.

  3. Finally, I change the scroll view content offset to some specific value.

However, a strange thing happens. Once I tap the text field, the scroll view animates to a content offset larger than the specific value, then immediately back to that specific value.

I suspected that both step 1 and 2 are the reasons for that so I excluded them and everything works just fine. However, this left me with part of the scroll view hidden below the keyboard.

EDIT: Here is the code I use (called when the text field starts editing):

        UIScrollView *scrollView = (UIScrollView *) self.view;

        if (scrollView.contentInset.bottom != C_SCROLL_VIEW_CONTENT_INSET_BOTTOM) {
            [scrollView setContentInset:UIEdgeInsetsMake(C_ORIGIN_ZERO,
                                                         C_ORIGIN_ZERO,
                                                         C_SCROLL_VIEW_CONTENT_INSET_BOTTOM,
                                                         C_ORIGIN_ZERO)];
            [scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(C_ORIGIN_ZERO,
                                                                  C_ORIGIN_ZERO,
                                                                  C_SCROLL_VIEW_CONTENT_INSET_BOTTOM,
                                                                  C_ORIGIN_ZERO)];
        }

        if (textField.tag == C_TAG_BUTTON) {
            [scrollView setContentOffset:CGPointMake(C_ORIGIN_ZERO, C_ORIGIN_SHIFT_SCROLL_VIEW_FOR_CURRENT_Y)
                                animated:YES];
            return;
        }
tilo
  • 14,009
  • 6
  • 68
  • 85
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79

1 Answers1

0

Assuming that C_SCROLL_VIEW_CONTENT_INSET_BOTTOM is your constant, I think that value is wrong (too big).

Juraj Antas
  • 3,059
  • 27
  • 37