Skip to content

Instantly share code, notes, and snippets.

@stevestreza
Created October 2, 2009 16:19
Show Gist options
  • Select an option

  • Save stevestreza/199870 to your computer and use it in GitHub Desktop.

Select an option

Save stevestreza/199870 to your computer and use it in GitHub Desktop.
- (void)keyboardWillHide:(NSNotification *)notification {
NSLog(@"%s %@", __PRETTY_FUNCTION__, notification);
double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve animationCurve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
// there's a handy category for doing this in UIGeometry.h
CGRect keyboardBounds = [(NSValue *)[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue];
[UIView beginAnimations:@"hideKeyboardAnimation" context:nil];
// make sure you put these calls ABOVE your "self.view.frame = ..." call
[UIView setAnimationCurve:animationCurve];
[UIView setAnimationDuration:animationDuration];
self.view.frame = CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
self.view.frame.size.height + keyboardBounds.size.height);
[UIView commitAnimations];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment