Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalesPageToFit not working properly running an iPhone app on iPad (iOS 7)

UIWebview scalesPageToFit is not working properly when running an iPhone app on iPad with iOS 7.

I set the scalesPageToFit = YES before loading the request to the WebView.

After the page loads, inspecting the HTML document width gives 769px while the UIWebView's scroll view frame width is 320. The scroll view zoomScale is 1 although you would expect it to be 0.41... (320/769). Any idea?

like image 383
sigabrt Avatar asked Oct 01 '13 12:10

sigabrt


2 Answers

The problem is now fixed in iOS 7.0.3. But, if you can't go there, please read on.

This seems to be a defect in iOS7. To recap, the problem happens when you run a iPhone only app, compiled with iOS7 SDK, in a iOS7 iPad or iPad Mini. A temporary work around is to scale the scroll view of the web view. This makes the text look smaller than you will like, but, so far, this is the best solution I have seen.

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    CGSize contentSize = webView.scrollView.contentSize;
    CGSize viewSize = self.view.bounds.size;

    float scale = viewSize.width / contentSize.width;
    if (scale < 0.9) {
        NSLog(@"Zoom out fix for web view: %f", scale);

        webView.scrollView.minimumZoomScale = scale;
        webView.scrollView.maximumZoomScale = scale;
        webView.scrollView.zoomScale = scale;
    }
}
like image 70
RajV Avatar answered Nov 05 '22 23:11

RajV


We have an ios-app and a webapp with the same integration problem. We had to solve this in the webapp by enforcing the 320 css. I consider this an ios7 bug and would expect a fix for this.

Same problem: https://twitter.com/lukew/status/380702676121825280

like image 2
user2837491 Avatar answered Nov 06 '22 00:11

user2837491