【发布时间】:2012-08-31 09:15:22
【问题描述】:
我是 iOS 新手,我正在尝试使用 SVGKit 在我的应用程序中呈现 svg 文件。我想从 URL 加载 svg 文件,但无法正常工作。我收到以下错误:
线程 1:EXC_BAD_Access(代码 = 2,地址 =0x0)
在以下行:SVGDocument.m 文件中的NSLog(@"[%@] SVGKit Parse error: %@", [self class], *error);。
我尝试通过使用已经存在的 SVGPad 示例来实现从 URL 加载文件,该示例可以完美地加载图片,但不能从 URL 加载。我使用此代码从 URL 加载图片:
NSString *urlString = [NSString stringWithFormat:@"http://upload.wikimedia.org/wikipedia/commons/6/66/Blank_Map-Africa.svg"];
NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
SVGDocument* svgDocument = [SVGDocument documentFromURL:url];
self.contentView = [[[SVGView alloc] initWithDocument:svgDocument] autorelease];
我还尝试使用以下代码创建我的简单应用程序,该应用程序仅从本地文件加载十张简单图片:
SecondViewController *vc = [[SecondViewController alloc] init];
NSString* svgFilename = [@"/Users/XCode Projects/SVGLink/Beastie" stringByAppendingPathExtension:@"svg"];
SVGDocument *svgDocument = [SVGDocument documentWithContentsOfFile:svgFilename];
vc.view = [[SVGView alloc] initWithDocument:svgDocument];
[self.window setRootViewController:vc];
我得到的只是这个错误:[SVGDocument] DEBUG INFO: set document viewBox = {{0, 0}, {340.961, 377.75}}
谁能解释我在哪里犯了错误?
我使用了这些版本的 SVGKit: https://github.com/SVGKit/SVGKit/
谢谢, 百合
编辑:
这个 SVG 套件版本 https://github.com/meric/SVGKit 可以完美地从 url 链接加载 .svg 文件,但我仍然从文件中遇到解析错误,例如脚本和其他无法识别的内容。 UIWebView 中的相同文件完美显示。我想转移到 SVG 解析器的唯一原因是,在旋转时 UIWebView 和 SVG 图形移动了几步,我找不到修复那个的方法。
【问题讨论】:
标签: iphone ios ipad svg rendering