如何在Objective-C的UIWebview中将.js文件加载到HTML中 [英] How to load .js file into HTML in UIWebview in Objective-C

查看:38
本文介绍了如何在Objective-C的UIWebview中将.js文件加载到HTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在现有的iOS应用中做一些wave动画.它由Objective-C语言实现.因此,我有.Js和HTML页面.在HTML页面中,我正在加载.js文件,并尝试使用UIWebview加载HTML文件.

I am doing some waves animation in my existing iOS app. Its implemented by Objective-C language. So, I have .Js and HTML pages. In HTML page, I am loading .js file and trying to loading HTML file with UIWebview.

但是,它始终显示空白的白屏,我也搜索了很多论坛,发现只能加载只能找到的HTML页面,找不到将UI文件加载到UIWebview的HTML页面中的

But, Always its showing Blank white screen, I searched so many forums too, I found only loading HTML pages only able to found, I din't found for loading .js file into HTML page for UIWebview.

//以下是我的代码.

@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,也得出了相同的结果.

Can anyone suggest me, how to fix this and load my animation code in Webview. Even I tried with WkWebview, but, same result came.

如果它是唯一没有.js的HTML文件,则会加载它,但是,如果我将.js文件包含到html文件中,则会显示空白屏幕.

If its only Html file without .js, its loading, but, if I inclued .js file into html file, its showing blank white screen.

推荐答案

问题是js文件代码无法正确加载HTML文件.这就是问题.我们终于修复了它.

The problem is js file code is not loading properly with HTML file. This is the issue. We have fixed it finally.

这篇关于如何在Objective-C的UIWebview中将.js文件加载到HTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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