UIWebView 在旋转后调整文本大小:寻找神奇错误或我的愚蠢的解释

UIWebView resizes text after rotating: looking for explanation for magical bug or my stupidity(UIWebView 在旋转后调整文本大小:寻找神奇错误或我的愚蠢的解释)

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

问题描述

所以我的应用程序中有 UIWebView 并加载了一些 html(文章),添加了一些 CSS 以使一切变得更好.这简单明了,一切都很完美,直到我尝试在横向功能中添加阅读,然后我注意到 UIWebView 忽略了我在 HTML 中放入的任何 css字体大小",并在旋转到横向模式后大幅增加字体大小.

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.

我花了大约 4-5 个小时(我是 Iphone 应用程序编程的新手,但在做正确的事情时我很固执)试图修复它.尝试了很多很多配置选项 - 没有.

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:

有虫子的风景:

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 来解决调整大小问题).

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).

我很高兴它可以工作,但我想知道如何和为什么,所以我可以以正确的方式"做到这一点,因为现在代码看起来很愚蠢,并且在应用程序底部有 1 点的高度边距.

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..

推荐答案

神奇的解决方案是:

<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 在旋转后调整文本大小:寻找神奇错误或我的愚蠢的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:UIWebView 在旋转后调整文本大小:寻找神奇错误或我的愚蠢的解释

基础教程推荐