iPhone Keyboard hiding fields in UIWebView

Posted by Pete on Stack Overflow See other posts from Stack Overflow or by Pete
Published on 2010-02-19T03:33:34Z Indexed on 2010/03/26 11:53 UTC
Read the original article Hit count: 673

Hi,

I am a beginner at iPhone development and am hoping someone can help me with my question.

I have a UIWebView displaying a web page. If the user taps inside a textbox on the web page then the keyboard pops up. This is great, but it hides the field that the user tapped on. I have looked around and found code samples to deal with this, but none that specifically deal with the UIWebView. I have implemented UIKeyboardDidShowNotification and UIKeyboardDidHideNotification but am not sure how to resize the UIWebView properly. I have tried putting the UIWebView in a UIScrollView but not had any success with that. The code below seems to adjust the UIWebView but won't let it scroll to the field.

-(void) keyboardDidShow: (NSNotification *)notif{
    if (keyboardShown) return;

    NSLog(@"Keyboard Show");
    NSDictionary *info = [notif userInfo];
    NSValue *aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey];
    CGSize keyboardSize = [aValue CGRectValue].size;

    CGRect viewFrame = webBrowser.frame;
    viewFrame.size.height -= keyboardSize.height;
    webBrowser.frame = viewFrame;
    keyboardShown = YES;
}

-(void) keyboardDidHide: (NSNotification *)notif{
    NSLog(@"Keyboard hide");
    keyboardShown = NO;

}

Hopefully someone can help me or point me in the right direction.

Thanks!

Pete

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone