Skip to content

Instantly share code, notes, and snippets.

@liamnichols
Created August 28, 2013 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liamnichols/6364410 to your computer and use it in GitHub Desktop.
Save liamnichols/6364410 to your computer and use it in GitHub Desktop.
#pragma mark - Keyboard Appearance
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary* info = [notification userInfo];
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrame = [self.view.window convertRect:keyboardFrame toView:self.view];
CGRect intersectRect = CGRectIntersection(self.view.frame, keyboardFrame);
self.toolbarBottomContraint.constant = -intersectRect.size.height;
[self.view animateLayoutIfNeededWithKeyboardUserInfo:info];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
self.toolbarBottomContraint.constant = 0;
[self.view animateLayoutIfNeededWithKeyboardUserInfo:notification.userInfo];
}
@end
@implementation UIView (LayoutAnimation)
- (void)animateLayoutIfNeededWithKeyboardUserInfo:(NSDictionary *)info
{
[UIView animateWithDuration:[[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]
delay:0
options:(UIViewAnimationOptions)([[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16)
animations:^{
[self layoutIfNeeded];
}
completion:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment