0

I am loading the url on the webview in iPad native App. It works fine so far, but in iOS7 when we click on the text filed, the content in webview is moving up. Please check the below code and screenshots. I try to fix by below posts , but didn't help.

iOS 7 input elements moving fixed positioned elements

UIWebView scrolling down on input focus iOS 6 only

self.webView.delegate=self;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strURL]]];

enter image description here

enter image description here

enter image description here

Community
  • 1
  • 1
Sudheer Kumar Palchuri
  • 2,919
  • 1
  • 28
  • 38

2 Answers2

0

If you are using UIWebview then you should set the min-height of the body tag to the inner height of the device. For example 460px for iPhone 4S or 520px for iPhone 5

Inner Height = Device height - Status bar height = 460px which should basically be the height of the app container.

document.addEventListener("deviceready", function(){
    var body = document.getElementsByTagName('body')[0];
    body.style.minHeight=window.innerHeight + 'px';
}, false);
Mani Kandan
  • 629
  • 4
  • 12
  • actually i am loading the webview using url. So how can i use the above code? – Sudheer Kumar Palchuri Dec 31 '13 at 13:28
  • I tried like below, but still issue is there, am i missing anything? NSString *javaScript=[NSString stringWithFormat:@"document.addEventListener(""deviceready"", function(){var body = document.getElementsByTagName('body')[0]; body.style.minHeight=window.innerHeight + 'px';}, false);"]; [self.webView stringByEvaluatingJavaScriptFromString:javaScript]; – Sudheer Kumar Palchuri Jan 02 '14 at 09:51
0

I had this problem, too. We have a custom class that inherits from UIWebView: CustomWebView. We were setting the web view's scrollView delegate to CustomWebView:

self.scrollView.delegate = self;

And we had scrollViewDidScroll defined to get callbacks when the page scrolls:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    // Do some stuff
}

However, in iOS 7 it appears that UIWebView is already a delegate for its scroll view, and therefore needs to receive scrollViewDidScroll to handle the scrolling properly. By removing my scrollViewDidScroll definition, or by adding

[super scrollViewDidScroll:scrollView]

to the start of my scrollViewDidScroll definition, I was able to solve this problem.

I hope this helps!

JMac
  • 31
  • 1
  • 3