【问题标题】:UIWebview Html5 with inline SVG带有内联 SVG 的 UIWebview Html5
【发布时间】:2011-08-08 03:34:03
【问题描述】:

我正在尝试在 Html 5 文件中使用 SVG 绘制一个基本圆圈,然后将其加载到 UIWebview 中。但是,当我编译并运行时,屏幕上什么也没有出现(在 iPad 上测试)。

我没有使用正确的代码还是 UIWebview 不支持带有 Html 5 的 SVG?

这是 UIWebview 的代码:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    NSString*  path    = [[NSBundle mainBundle] pathForResource:@"SVG" ofType:@"html"];
    NSString*  content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

    webView = [UIWebView new];
    webView.frame = CGRectMake(0, 0, 1024, 768);
    webView.dataDetectorTypes = UIDataDetectorTypeAll;
    webView.userInteractionEnabled = YES;
    [webView loadHTMLString:content baseURL:[[NSBundle mainBundle] bundleURL]];

    [self.view addSubview:webView];
    [webView release];
}

这是在资源文件夹中调用的 SVG.html 文件中的代码:

<!DOCTYPE html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
    <circle id="redcircle" cx="50" cy="50" r="50" fill="red" />
</svg>
</body>
</html>

我已经阅读了许多相关的帖子,但我无法找到答案。

感谢任何帮助。谢谢。

【问题讨论】:

    标签: iphone ios html uiwebview svg


    【解决方案1】:

    这是因为 Safari(或 UIWebView 中的内容)存在嵌入 SVG 元素的问题。我听说苹果会修复它,无论如何...
    试试这个:

    svg.html:

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>SVG</title>
      </head>
    
      <body>
        <object data="circle.svg" width="250" height="250"
        type="image/svg+xml" /> 
      </body>
    </html>
    

    圆.svg:

    <svg xmlns="http://www.w3.org/2000/svg">
    <circle r="50"/>
    </svg>
    

    【讨论】:

    • 太好了,成功了。希望我不必等待太久 Apple 即可解决此问题。但无论如何,我很感激周围的工作。谢谢!你得到了绿色的大勾号:)
    • 这可能是另一篇文章,但您知道如何从 html 文件中操作 SVG 吗?例如,将填充颜色更改为绿色。我知道如何在 SVG 文件中执行此操作,但我更愿意在 html 文件中执行此操作。如果你喜欢我可以开始另一个帖子,这样你就可以赢得另一个我只是想先问的问题。再次感谢。
    • 嘿,不要担心滴答声 :) 我做了一些研究,似乎 Safari 在 xml 文件中的内联 SVG 标签没有问题。请查看dl.dropbox.com/u/31624902/test.xml 以供参考。如果您需要任何帮助,请问我。
    • 嗯,我无法让它工作。只有按钮显示不三角形。我也将扩展名更改为 .xml。感谢您为我调查它。我是否需要像上面那样执行它?
    • 很高兴有帮助。在这个测试网站中,你有 JavaScript changeColor 函数,你可以直接在 xml 文件中调用它,或者在你的应用程序中调用它:[ yourWebView stringByEvaluatingJavaScriptFromString:@"changeColor();"];
    猜你喜欢
    • 1970-01-01
    • 2014-12-17
    • 2023-03-09
    • 2014-09-23
    • 2014-06-26
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多