UIWebView旋转后调整文本大小:寻找解释魔法bug或我的愚蠢 [英] UIWebView resizes text after rotating: looking for explanation for magical bug or my stupidity

查看:133
本文介绍了UIWebView旋转后调整文本大小:寻找解释魔法bug或我的愚蠢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有UIWebView在我的应用程序,我加载一些html(文章),它,放一些CSS,使一切更好。这简单明了,一切都是完美的,直到我尝试添加阅读的横向功能,然后我注意到UIWebView忽略任何cssfont-size我已经放在HTML和增加字体大小后旋转到横向模式。



我花了大约4-5个小时(我是新编程Iphone应用程序,但是当我做正确的事情时我很固执)尝试修理它。已尝试批次和大量配置选项 - 无。



今晚发生了神奇的事情。只需查看源代码:



风景与Bug

  r = CGRectMake(0.0,0.0,480.0,320.0); 
[adView.view removeFromSuperview];
if(!isFullScreen){
minus = 50 + minus;
[controlsView setFrame:CGRectMake(0,r.size.height - 50,r.size.width,50)];
} else {
minus = 20;
}

[textView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];
[scrollView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];

横向固定(字体大小不再更改): >

  r = CGRectMake(0.0,0.0,480.0,320.0) 
[adView.view removeFromSuperview];
if(!isFullScreen){
minus = 50 + minus;
[controlsView setFrame:CGRectMake(0,r.size.height - 50,r.size.width,50)];
} else {
minus = 20;
}
[textView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];
[scrollView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];

if(!isFullScreen){
minus = 1 + minus;
} else {
minus = 20 + 1;
}
[textView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];
[scrollView setFrame:CGRectMake(0,0,r.size.width,r.size.height - minus)];

正如你可以看到,我只添加了相同的代码一次,点。并再次setFrame(不,它不修复只有一组setFrames的调整大小)。



我很高兴它的工作,但我想知道HOW和WHY,所以我可以做到正确的方式,因为现在代码看起来愚蠢,在应用程序的底部有1点高的利润。



不要问为什么我试图复制粘贴相同的代码。

解决方案

而且神奇的解决方案是:

 < meta name ='viewport'content = width = device-width;初始尺度= 1.0; maximum-scale = 1.0;'> 

如果只有我知道这个星期前..这么多时间, / p>

so I have UIWebView in my application and I load some html (article) to it, put some CSS to make everything nicer. That's simple and clear and everything is perfect until I try to add reading in landscape functionality and then I've noticed that UIWebView ignores any css "font-size" I've put in HTML and increases font size drastically after rotating to landscape mode.

I've spent about 4-5 hours (I'm new to programming Iphone application, but I'm quite stubborn when it comes to making something right) trying to fix it. Tried lots and lots of configuration options - NOTHING.

And tonight something magical has happened. Just look at source:

Landscape with The Bug:

r = CGRectMake(0.0, 0.0, 480.0, 320.0);
[adView.view removeFromSuperview];
if (!isFullScreen) {
    minus = 50 + minus;
    [controlsView setFrame:CGRectMake(0, r.size.height - 50, r.size.width, 50)];        
} else {
    minus = 20; 
}

[textView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];  
[scrollView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];

Landscape fixed (font size does not change anymore):

r = CGRectMake(0.0, 0.0, 480.0, 320.0);
[adView.view removeFromSuperview];
if (!isFullScreen) {
    minus = 50 + minus;
    [controlsView setFrame:CGRectMake(0, r.size.height - 50, r.size.width, 50)];        
} else {
    minus = 20; 
}
[textView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];  
[scrollView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];

if (!isFullScreen) {
    minus = 1 + minus;
} else {
    minus = 20+1;   
}
[textView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];  
[scrollView setFrame:CGRectMake(0, 0, r.size.width, r.size.height - minus)];

As you can see I only added the same code one more time and increased margin (minus) by one point. And did setFrame again (no, it doesn't fix the resizing with only one set of setFrames).

I'm happy it works, but I would like to know HOW and WHY, so I can do it "right way", because now code looks stupid and have 1 point heigh margin at the bottom of application.

And don't ask why I've tried to copy paste the same code again..

解决方案

And the magical solution was:

<meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'>

If only I knew this week ago.. So much time, so much nerves got lost..

这篇关于UIWebView旋转后调整文本大小:寻找解释魔法bug或我的愚蠢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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