Forum Xamarin.iOS

UIWebView Creates empty space below textfield when keyboard appears

EswaraprabuEswaraprabu Member ✭✭
edited April 23 in Xamarin.iOS



I'm using UIWebView in Xamarin iOS for loading my webpage

When the keyboard appears extra space appearing between textfield and keyboard, I need to remove the unwanted space, Kindly help on this. Thanks in Advance

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Have you tried this approach on the webpage side:
    https://stackoverflow.com/a/13832007/8354952
    It could manually set the offset of the scroll view to (0, 0).

  • EswaraprabuEswaraprabu Member ✭✭

    Hi LandLu,

    Thanks for the suggestion.

    In my situation I don't have the control of the webpage. I'm only loading the url in UIWebView. Is their any way we can control it from UIWebview delegate in Xamarin ios

  • LandLuLandLu Member, Xamarin Team Xamurai

    Maybe there's some logic code on the webpage to move the webview.
    We could change its offset by registering the notification of keyboard:

    NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, async (notification) =>
    {
        await Task.Delay(100);
        webView.ScrollView.ContentInset = new UIEdgeInsets(0, 0, 0, 0);
        webView.ScrollView.ContentOffset = new CGPoint(0, 0);
    });
    

    Moreover, UIWebView now has been deprecated by Apple it's better to move to WKWebView.

Sign In or Register to comment.