我正在尝试为iOS应用程序实现360°旋转。我的目标是在HTML上完成并加载到UIWebView中。
我尝试过的:
我使用JQuery卷轴插件进行360°旋转。
我的HTML代码看起来像:
<script src="JQuery.js" type="text/javascript"></script>
<script src="reel.js" type="text/javascript"></script>
<img src="images/360_1.jpg" width="480" height="360"
class="reel"
data-images="images/360_#.jpg|1..36"
data-frames="10"
data-footage="2"
data-revolution="800">
结果:
这适用于Windows(Firefox、Chrome和IE)和Mac操作系统(Safari)。但在iOS UIWebView
中,它只显示初始图像而不旋转。
iOS代码:
在iOS中,我将整个文件添加到我的项目中,并加载页面,如:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
也尝试过:
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webviewloadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];
但没有什么能解决我的问题,请帮帮我。
最后,我通过以下步骤解决了这个问题。
1)通过在XCode
中选择"Create folder references for any added folders"
,将包含HTML文件的文件夹添加为"Reference"。
2)我使用以下代码加载HTML,它成功了:
// 360 is the folder which contains the HTML files
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"360"]];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];