Reset the UIWebView zoom value using java script
Instead of loadRequest: method of UIWebview, I am loading the UIWebview content using the java script for faster loading. I have only one web view in my application and depending upon the selection in the table view, web view's content will be changed. There is also a pinch zoom support for the web view. Now the problem I am facing is with resetting the zoom factor to default value when the table view selection changes.
For Example: Lets say I am viewing the content for some selection in table view and I will pinch zoom and the zoom factor is set to the maximum value say 5.0. Now if I change the selection in table view, I want the content to be loaded using the default zoom factor i,e 1.0.
I have tried using the java script code I found in net. Please refer the code below.
meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; minimum-scale=1.0 maximum-scale=5.0;\"
Unfortunately,zoom factor is not reset by using this code. But I am able to set the maximum scale factor for the UIWebview. Please let me 开发者_如何学JAVAif anyone knows solution for this.
[PS: If we use UIWebview's loadRequest: method and set scalesPageToFit property to YES then, UIWebView itself handles this issue]
Aside from using that Javascript, you should also setZoomScale the scrollview of your webview.. And also call scrollViewDidEndZooming of your webview.
I also used setContentSize of scrollview to enlarge the scrollview as the webview grows bigger too.
This is only a workaround I discovered.
精彩评论