Skip to content

Instantly share code, notes, and snippets.

@jyliang
Last active August 29, 2015 14:02
Show Gist options
  • Save jyliang/f6073a4c8ed2b69fbb0a to your computer and use it in GitHub Desktop.
Save jyliang/f6073a4c8ed2b69fbb0a to your computer and use it in GitHub Desktop.
- (void)registerKeyboardNotifications {
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[dnc addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (void)unregisterKeyboardNotifications {
NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter];
[dnc removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[dnc removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[dnc removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[dnc removeObserver:self name:UIKeyboardDidHideNotification object:nil];
}
- (void)keyboardWillShow:(id)notification {
NSDictionary* keyboardInfo = [notification userInfo];
CGFloat keyboardHeight = [[keyboardInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size.height;
}
- (void)keyboardWillHide:(id)notification {
}
- (void)keyboardDidShow:(id)notification {
}
- (void)keyboardDidHide:(id)notification {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment