Created
October 15, 2013 12:08
-
-
Save JigsChanchiya/6990562 to your computer and use it in GitHub Desktop.
Keybord notifications in OS
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
/* | |
UIKeyboardWillShowNotification | |
UIKeyboardDidShowNotification | |
UIKeyboardWillHideNotification | |
UIKeyboardDidHideNotification | |
*/ | |
- (void)viewDidLoad { | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillShow:) | |
name:@"UIKeyboardWillShowNotification" | |
object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardDidHide:) | |
name:@"UIKeyboardDidHideNotification" | |
object:nil]; | |
} | |
- (void) keyboardWillShow:(NSNotification *)note { | |
NSDictionary *userInfo = [note userInfo]; | |
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; | |
NSLog(@"Keyboard Height: %f Width: %f", kbSize.height, kbSize.width); | |
// move the view up by 30 pts | |
CGRect frame = self.view.frame; | |
frame.origin.y = -30; | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.view.frame = frame; | |
}]; | |
} | |
- (void) keyboardDidHide:(NSNotification *)note { | |
// move the view back to the origin | |
CGRect frame = self.view.frame; | |
frame.origin.y = 0; | |
[UIView animateWithDuration:0.3 animations:^{ | |
self.view.frame = frame; | |
}]; | |
} | |
- (void) dealloc { | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; | |
// uncomment for non-ARC: | |
// [super dealloc]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment