Skip to content

Instantly share code, notes, and snippets.

@MP0w
Created January 2, 2014 09:19
Show Gist options
  • Save MP0w/8216753 to your computer and use it in GitHub Desktop.
Save MP0w/8216753 to your computer and use it in GitHub Desktop.
Fix iOS 7 texview that doesn't scroll properly while you type
- (void)textViewDidChange:(UITextView *)textView {
CGRect line = [textView caretRectForPosition:
textView.selectedTextRange.start];
CGFloat overflow = line.origin.y + line.size.height
- ( textView.contentOffset.y + textView.bounds.size.height
- textView.contentInset.bottom - textView.contentInset.top );
if ( overflow > 0 ) {
CGPoint offset = textView.contentOffset;
offset.y += overflow + 7;
[UIView animateWithDuration:.2 animations:^{
[textView setContentOffset:offset];
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment