I have a UIScrollView inside which I have a UITextField and a UITextView. I want the keyboard not to hide the field we're working on. If my user clicks on a TextField, I want it to scroll to the top of the screen. If my user touches the TextView, I want him to resize to the empty space left at the top of the keyboard. My keyboard has an additional view (toolbar).
I am currently catching a UIKeyboardWillShowNotification notification, and I am using this code, which actually does not work (the text image has been changed, but is still behind the keyboard): This code worked well when I did not have a UIScrollView.
- (void)keyboardWillShow:(NSNotification *)notification {
if ([self.noteView isFirstResponder] == NO) return;
NSDictionary *userInfo = [notification userInfo];
NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
CGFloat keyboardTop = keyboardRect.origin.y;
CGRect newTextViewFrame = self.view.bounds;
newTextViewFrame.size.height = keyboardTop - self.view.frame.origin.y;
NSTimeInterval animationDuration;
[animationDurationValue getValue:&animationDuration];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:animationDuration];
self.noteView.frame = newTextViewFrame;
[UIView commitAnimations];
}
: