skyylex / SKEPReader

ePub reader example based on the https://github.com/fedefrappi/AePubReader
1 stars 3 forks source link

Zooming images in the epub #2

Open skyylex opened 9 years ago

skyylex commented 9 years ago

Add support of the zooming feature

zlpcrmm commented 9 years ago

I have add an JS script in the webview did load method already resolved the issue. NSString zoomImage = [NSString stringWithFormat:@"var script = document.createElement('script');" "script.type = 'text/javascript';" "script.text = \"function ResizeImages() { " "var myimg,oldwidth;" "var maxwidth=%f;" "for(i=0;i <document.images.length;i++){" "myimg = document.images[i];" "if(myimg.width > maxwidth){" "oldwidth = myimg.width;" "myimg.width = maxwidth;" "myimg.height = myimg.height \ (maxwidth/oldwidth);" "}" "}" "}\";" "document.getElementsByTagName('head')[0].appendChild(script);",self.webView.frame.size.width-20]; [self.webView stringByEvaluatingJavaScriptFromString:zoomImage]; [self.webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];

skyylex commented 9 years ago

Thank you for solution's sharing. The alternative way for this is to insert an additional CSS file with image attributes. Did you check for performance and appearance issues? It's interesting to compare what will be work faster on huge amount of images (or for several huge images), and another question related to the appearing of such effect, is it smooth enough?