Skip to content

Instantly share code, notes, and snippets.

@jeksys
Created February 11, 2012 07:04
Show Gist options
  • Save jeksys/1797397 to your computer and use it in GitHub Desktop.
Save jeksys/1797397 to your computer and use it in GitHub Desktop.
KeyboardHide show
[[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