UIWebView 出现奇怪的闪烁
当推送一个包含 UIView > 的新 viewController 时,我有这种奇怪的(短暂的)闪烁。 UIWebView。
在包含 UIWebView 的controller.m 内部,我为 webView 设置了以下代码:
//EXAMPLE 1
NSString *path = [[NSBundle mainBundle]bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString htmlData = [NSString stringWithFormat:@"<样式类型=\"text/css\"> { margin:0; padding:0; }body {背景颜色:#c6c6c6;宽度:320px;字体大小:13px;颜色:#404a52;
%@
%@
%@
%@
< !-- meddelingenContent -->", titleString, dateString,authorString,filteredDescription ];
[webView loadHTMLString:htmlDatabaseURL:baseURL];
使用此代码,当将此控制器推到窗口上时,会出现闪烁。但是,如果我将 htmlData 更改为更简单的内容(例如下面的代码),而不使用例如 css,闪烁就会突然消失。
//EXAMPLE 2
NSString *htmlData = [NSString stringWithFormat:@"<html><head></head><body><h1>Some Header!</h1><p>Some text</p></body></html>"];
那么有没有一种方法可以在我的 NSBundle 中加载 .html 文件并将 NSString 分配给某些 HTML 内容,就像我在示例 1 中对 htmlData 所做的那样?或者有没有更好的方法来做到这一点?
谢谢!
I have this strange (short) flickering when pushing a new viewController which contains a UIView > UIWebView.
Inside the controller.m, which contains the UIWebView, I have this code setup for the webView:
//EXAMPLE 1
NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString htmlData = [NSString stringWithFormat:@"<html><head><style type=\"text/css\"> { margin:0; padding:0; }body { background-color:#c6c6c6; width: 320px; font-family: Helvetica; font-size:13px; line-height: 18px; color:#404a52; } #someOtherStyles...</style></head><body><div id=\"mededelingenDetailViewHeader\"><h1>%@</h1><p class=\"date\">%@</p><p class=\"author\">%@</p></div><div id=\"mededelingenDetailViewContent\"><p>%@</p></div><!-- mededelingenContent --></body></html>", titleString, dateString, authorString, filteredDescription ];
[webView loadHTMLString:htmlData baseURL:baseURL];
With this code the flickering shows up when pushing this controller onto the window. But if I change the htmlData to something simpler like the code below without for e.g. css the flickering suddenly dissappears.
//EXAMPLE 2
NSString *htmlData = [NSString stringWithFormat:@"<html><head></head><body><h1>Some Header!</h1><p>Some text</p></body></html>"];
So is there a way to load an .html file inside my NSBundle and assign NSString to some HTML contents like I did with htmlData in example 1? Or is there any better way to do this?
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[webView loadHTMLString:htmlData baseURL:baseURL];
是从 viewDidAppear 调用的吗?如果是这样,那就可以解释闪烁:它在用户观看时加载 HTML。将该调用移至 viewDidLoad 并查看是否可以解决问题。Is
[webView loadHTMLString:htmlData baseURL:baseURL];
called from viewDidAppear? If so, that would explain the flicker: it's loading the HTML while the user watches. Move that call to viewDidLoad and see if that solves it.