1
votes

UITextView becomes first responder when user taps on a button to add a UITextView on UIScrollView. Actually UIView which contains UITextView or UITextField is added in UIScrollView. When keyboard appears, scrollview does not scroll up, however UITextField makes it scrolling up when it becomes first responder. I register UIKeyboardDidShowNotification to scroll up. Below is my code

- (void)keyboardDidShow:(NSNotification *)notification {
        CGRect keyboardEndFrame;
        [(notification.userInfo)[UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];

        NSInteger height = CGRectGetHeight(keyboardEndFrame);

        NSInteger lastObj = arrayTotalObjects.count - 1;
        UIView *lastView = [arrayTotalObjects objectAtIndex:lastObj];

        if(!(lastView.frame.origin.y > height))
            return;

        UIEdgeInsets inset = originalInset;
        inset.bottom += height;
        NSLog(@"inset: %f", inset.bottom);

        [UIView animateWithDuration:0.3f animations:^{
            scrlView.contentInset = inset;
        }completion:^(BOOL finished) {
            NSLog(@"scrlView inset bottom: %f", scrlView.contentInset.bottom);
        }];
}

In this case lastView will be UIView containing UITextView.

This code works for UITextField but not for UITextView. How is that possible? Is it because UITextView is subclass of UIScrollView?

2

2 Answers

0
votes

If someone see this question, The answer is set UITextView scrolling enabled false

In lawicko's answer, I got a hint. subclass of UIScrollView.

It works to me.

-1
votes

In short, the answer to your question is yes, this behavior is caused by UITextView being a subclass of UIScrollView. You can find more details, as well as the solution how to disable it, here.