2011-06-26 66 views
0

放大Web視圖我用這個代碼變焦:HOWTO捏上一個UIWebView [JS回調]在iPhone,iPod touch和iPad

<body id='body'> 
     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt u,... 

    <script type="text/javascript" charset="utf-8"> 

     body = document.getElementById('body'); 

     // (in percents) 
     zoom = 100; 
     maxZoom = 200; 
     minZoom = 50; 
     zoomIncrement = 25; 

     function gestureEnd(event) { 
      var newZoom; 
      if (event.scale > 1.0) { 
       // increase size 
       newZoom = zoom + zoomIncrement; 
      } else { 
       // decrease size 
       newZoom = zoom - zoomIncrement; 
      } 

      // don't exceed zoom boundaries 
      if (newZoom > maxZoom || newZoom < minZoom) { 
       return; 
      } 
      zoom = newZoom; 
      body.style.webkitTextSizeAdjust = zoom+"%"; 
     } 

     body.addEventListener("gestureend", gestureEnd, false); 

     </script> 
    </body> 

我怎麼可以具有的WebView焦距可變值每捏事件(更改APP中的默認值)??

一類的「回調」由JS到App方法..

回答

0

如果你想獲得一個JS變量的值在應用原生的OBJ-C使用,也許你可以使用stringByEvaluatingJavaScriptFromString方法。

+0

謝謝! 我會嘗試這種方法,但我確定這是我正在尋找的! – ikanimo