Skip to content

Instantly share code, notes, and snippets.

- (void)subscribeToKeyboardEvents:(BOOL)subscribe{
if(subscribe){
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}else{
- (void)viewWillDisappear:(BOOL)animated{
[self subscribeToKeyboardEvents:NO];
}
- (void)viewDidAppear:(BOOL)animated{
[self subscribeToKeyboardEvents:YES];
}