keyboard settings

// Keyboard Settings

- (void)registerForKeyboardNotifications {

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification
object:nil];

}

- (void)deregisterFromKeyboardNotifications {

[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardDidHideNotification
object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];

}
- (void)keyboardWasShown:(NSNotification *)notification {

NSDictionary* info = [notification userInfo];

CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

CGPoint buttonOrigin = self.submitButton.frame.origin;

CGFloat buttonHeight = self.submitButton.frame.size.height;

CGRect visibleRect = self.view.frame;

visibleRect.size.height -= keyboardSize.height;

if (!CGRectContainsPoint(visibleRect, buttonOrigin)){

CGPoint scrollPoint = CGPointMake(0.0, buttonOrigin.y - visibleRect.size.height + buttonHeight);

[self.registerScrollView setContentOffset:scrollPoint animated:YES];

}

}

- (void)keyboardWillBeHidden:(NSNotification *)notification {

[self.registerScrollView setContentOffset:CGPointZero animated:YES];

}
- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

[self registerForKeyboardNotifications];

}

- (void)viewWillDisappear:(BOOL)animated {

[self deregisterFromKeyboardNotifications];

[super viewWillDisappear:animated];

}
Previous
Next Post »