scalesPageToFit无法正常运行iPad上的iPhone应用程序(iOS 7) [英] scalesPageToFit not working properly running an iPhone app on iPad (iOS 7)

查看:253
本文介绍了scalesPageToFit无法正常运行iPad上的iPhone应用程序(iOS 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 iOS 7 iPad 上运行 iPhone 应用时, UIWebview scalesPageToFit 无效。



在将请求加载到WebView之前,我设置了 scalesPageToFit = YES



页面加载后,检查HTML文档宽度为769px,而UIWebView的滚动视图框架宽度为320.滚动视图zoomScale为1,但您可以预期它为0.41 ...(320/769)。任何想法?

解决方案

此问题现已在iOS 7.0.3中修复。但是,如果你不能去那里,请继续阅读。



这似乎是iOS7中的一个缺陷。回顾一下,当您在iOS7 iPad或iPad Mini中运行使用iOS7 SDK编译的仅iPhone应用程序时,会出现问题。临时解决方法是缩放Web视图的滚动视图。这使得文本看起来比你想要的要小,但到目前为止,这是我见过的最佳解决方案。

   - (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(@缩小网页视图的修正:%f,比例);

webView.scrollView.minimumZoomScale = scale;
webView.scrollView.maximumZoomScale = scale;
webView.scrollView.zoomScale = scale;
}
}


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?

解决方案

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;
    }
}

这篇关于scalesPageToFit无法正常运行iPad上的iPhone应用程序(iOS 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆