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
?