如何允许缩放UIWebView(尝试一切) [英] How to allow zooming of UIWebView (tried everything)

查看:109
本文介绍了如何允许缩放UIWebView(尝试一切)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了每一段我已经发现的尝试使这一页放大和缩小的代码,但无论如何,文本仍然与屏幕重叠,并且UIWebView中的页面将无法适应屏幕。



我试过这里的指示: http://www.iphonedevsdk.com/forum/iphone-sdk-development/9112-uiwebview-zoom-pinch.html



我尝试添加: webView.scalesPageToFit = TRUE;



将它设置为 UserInteractionEnabled



但是没有任何效果。



这与网页编码有关,还是与UIWebView有关?

谢谢,



James

解决方案


  1. 首先。请参阅UIWebView类参考,您需要设置scalesPageToFit。



    Apple说:
    scalesPageToFit
    如果是,网页将缩放以适合用户可以放大和缩小。如果否,则禁用用户缩放。如果您查看页面的源代码,您应该可以找到// meta name =viewportcontent =

  2. width = device-width; initial-scale = 1.0; maximum-scale = 1.0;//.



    为了向您展示缩放效果。我想用它替换它:
    // meta name =viewportcontent =width = device-width; initial-scale = 1.0; maximum-scale = 5.0; user-scalable = 1;// //。

  3. b
    $ b

     函数setScale(){
    var all_metas = document.getElementsByTagName('meta');
    if(all_metas){
    var k; (k = 0; k var meta_tag = all_metas [k];
    ;
    var viewport = meta_tag.getAttribute('name');
    if(viewport&& viewport =='viewport'){
    meta_tag.setAttribute('content','width = device-width; initial-scale = 1.0; maximum-scale = 5.0; user -scalable = 1;);
    }

    }
    }
    }



I have tried literally every bit of code I have found to try and make this one page zoom in and out but no matter what, the text still overlaps the screen and the page in the UIWebView will simply not fit to the screen.

I've tried instructions here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/9112-uiwebview-zoom-pinch.html

I've tried adding: webView.scalesPageToFit = TRUE;

I've set it to UserInteractionEnabled.

But nothing seems to work at all.

Is this to do with the coding of the webpage or is it to do with the UIWebView?

Thank you,

James

解决方案

  1. First of all. Refer to UIWebView Class reference, you need to set scalesPageToFit.

    Apple says: scalesPageToFit If YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.

  2. If you view the source of the page, you should be able to find //meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"//.

    In order to show you the Zoom effect. I want to replace it with: //meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=5.0; user-scalable=1;"//.

  3. Run the following javascript for UIWebview's method stringByEvaluatingJavaScriptFromString: in - (void)webViewDidFinishLoad:(UIWebView *)webView{ }

    function setScale(){
    var all_metas=document.getElementsByTagName('meta');
    if (all_metas){
        var k;
        for (k=0; k<all_metas.length;k++){
            var meta_tag=all_metas[k];
            var viewport= meta_tag.getAttribute('name');
            if (viewport&& viewport=='viewport'){
                meta_tag.setAttribute('content',"width=device-width; initial-scale=1.0; maximum-scale=5.0; user-scalable=1;");
            }
    
        }
    }    
    }
    

这篇关于如何允许缩放UIWebView(尝试一切)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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