I have a project that requires large SVG files to be rendered. So far I've been using a UIWebView, which works, but can take upwards of 10 seconds to render. On older devices the app just runs out of memory.
I've come up with several possible solutions:
- Use a CATiledLayer (but I couldn't find any way to do this with svg)
- Rasterize the SVGs first, split them up, then use a tiled layer (this would be really slow on the first run, though)
- Use PDF instead (although im not sure if this would help at a开发者_运维问答ll wth vector - anyone with prior experience?)
The SVGs are generated server-side, so im open to suggestions on that front too (I.e. changing formats)
I'd appreciate some pointers from people who have experience in this area in choosing a way forward. You have my sincere thanks!
Okay! After much trial and error I believe I have a buttery smooth scrollview of massive SVGs in iOS.
Basically, you need to cut up your svg into tiles and use UIWebViews to render them within a UIScrollView.
Make sure you load the tiles asynchronously from the main thread, which can be tricky because you can't do stuff to UIWebView from a background thread. You'll suffer from choppy framerates if you try and load the tiles in scrollviewdidscroll.
Also, you might want to use a small reset css in your UIWebViews to get rid of ugly padding around your tiles.
* {
margin:0;
padding:0;
}
did it for me.
PDF is the native format of Adobe Illustrator and well supported on iOS, so it's definitely an option for vector graphics. Rendering complex vector graphics is always very CPU-heavy though, so you'll have to experiment to find out what is faster. Given that the PDF stack on iOS is much more mature than SVG support in WebKit, I would guess that it could be faster but it depends a lot on your input files. You could check out the ZoomingPDFViewer sample code from Apple which uses CATiledLayer
with PDF to get started.
I wrote a system that can handle large SVG files that Inkscape cannot. It converts SVG into JavaScript and HTML. The public version runs on a webserver that is slower than my development environment. I would like to test what you call a large SVG. If it works it will create the SVG in JavaScript and HTML and will fender the SVG so that a user would see it being built. Is it possible that you could send a medium and large SVG so that I could try converting them in both dev and test?
Excuse spelling-ipod
精彩评论