Skip to content

Instantly share code, notes, and snippets.

@meiwin
Created July 2, 2012 16:46
Show Gist options
  • Save meiwin/3034192 to your computer and use it in GitHub Desktop.
Save meiwin/3034192 to your computer and use it in GitHub Desktop.
resizing view on keyboard apperance/disapperance
#pragma mark - Handle Keyboard Appearance/Disappearance
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
kbRect = [self.view convertRect:kbRect toView:nil];
CGRect viewRect = [self.view convertRect:self.view.frame fromView:nil];
CGRect newRect = CGRectMake(viewRect.origin.x
,viewRect.origin.y
,viewRect.size.width
,viewRect.size.height-kbRect.size.height);
self.view.frame = [self.view convertRect:newRect toView:nil];
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
kbRect = [self.view convertRect:kbRect toView:nil];
CGRect viewRect = [self.view convertRect:self.view.frame fromView:nil];
CGRect newRect = CGRectMake(viewRect.origin.x
,viewRect.origin.y
,viewRect.size.width
,viewRect.size.height+kbRect.size.height);
self.view.frame = [self.view convertRect:newRect toView:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment