Skip to content

Instantly share code, notes, and snippets.

@mjjimenez
Created December 15, 2013 00:45
Show Gist options
  • Save mjjimenez/7967112 to your computer and use it in GitHub Desktop.
Save mjjimenez/7967112 to your computer and use it in GitHub Desktop.
Animate scrolling to new content offset when keyboard appears in iOS 7.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[info[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[info[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];
self.textViewKeyboardConstraint.constant = height;
UIEdgeInsets insets = UIEdgeInsetsMake(
scrollView.contentInset.top, 0, textView.bounds.size.height + height, 0);
scrollView.contentInset = insets;
scrollView.scrollIndicatorInsets = insets;
[view layoutIfNeeded];
[scrollView setContentOffset:CGPointMake(0, newOffset) animated:NO];
[UIView commitAnimations];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment