I have a simple UIScrollView with one text field I am trying to get to scroll when the keyboard appears. I have been trying to run code which is almost identical to that in the iPhone Application Developer's guide to accomplish this. The code compiles cleanly, runs cleanly, but absolutely nothing happens -- there is no scrolling whatsoever. Here is the code:
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
if (keyboardShown)
return;
NSDictionary* info = [aNotification userInfo];
// Get the size of the keyboard.
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
// Resize the scroll view (which is the root view of the window)
CGRect viewFrame = [self.view frame];
viewFrame.size.height -= keyboardSize.height;
self.view.frame = viewFrame;
// Scroll the active text field into view.
CGRect textFieldRect = [searchStringTextField frame];
UIScrollView *scrollView = (UIScrollView *)self.view;
[scrollView scrollRectToVisible:textFieldRect animated:YES];
keyboardShown = YES;
}
I've run this thing through the debugger, and all variables seem to populated properly, but absolutely nothing happens to the view that needs to be scrolled. Any ideas what might be the problem here?
Thanks,
Brad