UIWebView frame resize does not resize the inner content
if I change the frame of a UIWebView (scalesPageToFit property is YES), what do I have to do that the zooming level of a currently displayed webpage persists?
Let's say I have a UIWebView frame with a width of 200 pixels, and has zoomed into a website so that only one column is visible. After changing the width to 300, I still see the column with the same size, and additional space at the left and right. But what I would need is that I still only see this column, but bigger.
Any ideas what I have to do to achive this? I tried a lot of things, but nothing worked so far.
By the way, the iPhone built in Safari browser does exactly this thing (with the same website, so it's not conte开发者_Go百科nt related) when rotating the iPhone... I see the same content, bug bigger, NOT more content as it happens with my current version of code.
Thanks for helping! Markus
EDIT: Better answer:
mjdth is correct, you can use the contentMode
property on the UIWebView
. Very simple:
webView.contentMode = UIViewContentModeRedraw;
Old, crap answer:
This worked for me, but I was working with local pages and small amounts of content:
-(void)layoutSubviews
{
// Cause web view to reload content in order to display at new frame size
[webView reload];
}
I'd love to see a better solution that doesn't involve reloading the page though!
What do you have set for the webview's UIViewContentMode (can also be set in IB under the View section's "Mode")? Since you're resizing the view it may have something to do with this. Just a shot in the dark since I haven't tried it but hopefully this helps.
You may also want to try turning off scalesPageToFit before the transition and turning it back on after.
精彩评论