Ios8 UIWebview svg embaded html not show

I recently worked on an svg map application. everything works fine on ios7. when i transfer my project to ios8. strange things happened, I found that when a UIWebview reads a local html file into which the svg file is embedded, the svg file will not display on ios8.

code example:

@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]; NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path]; NSURLRequest *req = [NSURLRequest requestWithURL:fileURL]; [self.webView loadRequest:req]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end 

and the html file used:

 <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>SVG DEMO</title> </head> <body> <div> <embed src="410.svg" width="64" height="64" type="image/svg+xml" /> <object type="image/svg+xml" data="410.svg" width="64" height="64" border="1"></object> </div> </body> </html> 

Does anyone know what is going on?

thanks

+5
source share
4 answers

I had the same problem with my application. And I found this solution:

 <!DOCTYPE html> <html> <head> <title>Informations</title> </head> <body> <center><img src="logo.svg" width="200" height="200" /></center> </body> </html> 

Works with iOS 7.0.3 and 8.0

+5
source

I noticed that SVGs that had an animated tag seemed fine, while those that didn't have one didn't appear. Adding a dummy animation tag to svg is a temporary solution that I am using.

 ... <animate attributeName="opacity" values="0.99;1.0" dur="0.01s" begin="0s" repeatCount="1"></animate> </svg> 

Update:

This problem has been fixed in iOS 8.1.2 (possibly earlier), so it is no longer needed.

+3
source

Using this solution How do I get WebKit to redraw / redraw to propagate style changes? solved this for me without changing the HTML structure through the image (I needed svg to remain nested).

So my last code is something like:

 var emb = document.querySelector( '.myCSSClass'); svgItem = emb.getSVGDocument.getElementsByTagName('svg')[0] svgItem.style.display='none'; var somethinguseless = svgItem.offsetHeight; // SHOULD not need to store this anywhere, the reference is enough. Without a ref, the closure compiler removes it svgItem.style.display='block'; 
0
source

just FYI: I tested the iOS 8.1 update this morning when the SVGs in the embed tags are fixed ...

0
source

Source: https://habr.com/ru/post/1202837/


All Articles