- (void)viewDidLoad
{
[super viewDidLoad];
[self registerForKeyboardNotifications];
}
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillBeShown:(NSNotification*)aNotification
{
NSDictionary *dictionary = [aNotification userInfo];
CGRect keyboardRect = [[dictionary objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval duration = [[dictionary objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve animationCurve = [[dictionary objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
[UIView animateWithDuration:duration
delay:0.0f
options:animationCurve
animations:^{
CGPoint scrollPoint = CGPointMake(0, keyboardRect.size.height);
[self.scrollView setContentOffset:scrollPoint animated:YES];
}
completion:nil];
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
[self.scrollView setContentOffset:CGPointZero animated:YES];
}