Created
August 28, 2013 10:05
-
-
Save liamnichols/6364410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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