【发布时间】:2018-05-04 02:48:18
【问题描述】:
我正在现有的 iOS 应用中制作一些波浪动画。它由Objective-C语言实现。 所以,我有 .Js 和 HTML 页面。在 HTML 页面中,我正在加载 .js 文件并尝试使用 UIWebview 加载 HTML 文件。
但是,总是显示空白屏幕,我也搜索了很多论坛,我发现只有加载HTML页面才能找到,我没有找到将.js文件加载到UIWebview的HTML页面。
// 以下是我的代码。
@property (nonatomic, weak) IBOutlet UIWebView *animationView;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePathh=[[NSBundle mainBundle]pathForResource:@"voicewave" ofType:@"html" inDirectory:nil];
NSLog(@"%@",filePathh);
NSString *htmlstring=[NSString stringWithContentsOfFile:filePathh encoding:NSUTF8StringEncoding error:nil];
// [_animationView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePathh]]];
[_animationView loadHTMLString:htmlstring baseURL:nil];
}
而HTML代码是
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<style>
.container {
background: rgba(232, 17, 17, 0);
}
</style>
<body>
<div id="container-ios9" class="container"></div>
<script src="wave9.js"></script>
<script>
var $wave_ios9 = document.getElementById('container-ios9');
var SW9 = new Wave9({
height: 40,
speed: 0.2,
amplitude: 0.1,
container: $wave_ios9,
autostart: false,
});
</script>
</body>
</html>
谁能建议我,如何解决这个问题并在 Webview 中加载我的动画代码。即使我尝试过使用 WkWebview,但结果还是一样。
如果它只有一个没有 .js 的 Html 文件,它会加载,但是,如果我将 .js 文件包含到 html 文件中,它会显示空白屏幕。
【问题讨论】:
-
@Savitha 对这个问题有什么想法吗?
标签: html ios objective-c iphone webview