Created
February 11, 2012 07:04
-
-
Save jeksys/1797397 to your computer and use it in GitHub Desktop.
KeyboardHide show
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
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillShown:) | |
name:UIKeyboardWillShowNotification | |
object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillHide:) | |
name:UIKeyboardWillHideNotification | |
object:nil];} | |
#pragma mark - keyboard | |
- (void)keyboardWillShown:(NSNotification *)notification | |
{ | |
NSDictionary* info = [notification userInfo]; | |
CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
keyboardFrame = [self.view convertRect:keyboardFrame toView:self.view]; | |
CGSize keyboardSize = keyboardFrame.size; | |
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey]; | |
NSTimeInterval duration = 0; | |
[value getValue:&duration]; | |
[UIView animateWithDuration:duration animations:^{ | |
keyboardToolBar.center = CGPointMake(keyboardToolBar.center.x, self.view.bounds.size.height - (keyboardSize.height + keyboardToolBar.frame.size.height) - 20); | |
}]; | |
} | |
- (void) keyboardWillHide:(NSNotification *)notification { | |
NSDictionary* info = [notification userInfo]; | |
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey]; | |
NSTimeInterval duration = 0; | |
[value getValue:&duration]; | |
[UIView animateWithDuration:duration animations:^{ | |
keyboardToolBar.center = CGPointMake(keyboardToolBar.center.x, self.view.bounds.size.height + keyboardToolBar.frame.size.height/2); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment