mchoe / SwiftSVG

A simple, performant, and lightweight SVG parser
Other
1.94k stars 229 forks source link

Cannot create 2 SVGViews with one svg image data #100

Open mucdong opened 6 years ago

mucdong commented 6 years ago
var svgView = UIView(SVGNamed: "mySVG", parser: nil, completion: { (svgLayer) in
            svgLayer.resizeToFit(CGRect(x: 0, y: 0, width: 20, height: 20))
            svgLayer.frame.origin = CGPoint(x: 0, y: 15
            svgLayer.fillColor  = color.cgColor
        })
        svgView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
        svgView.backgroundColor = UIColor.clear
        self.myView1.addSubview(svgView)

svgView = UIView(SVGNamed: "mySVG", parser: nil, completion: { (svgLayer) in
            svgLayer.resizeToFit(CGRect(x: 0, y: 0, width: 20, height: 20))
            svgLayer.frame.origin = CGPoint(x: 0, y: 15
            svgLayer.fillColor  = color.cgColor
        })
svgView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
svgView.backgroundColor = UIColor.clear
self.myView2.addSubview(svgView)

I create 2 SVGViews and add into 2 UIView (myView1, myView2), but don't know why only myView2 displaya svg data, the myView1 didn't. But if I clone mySVG.svg and edit it to a new svg file, and load into myView2, all worked well

var svgView = UIView(SVGNamed: "mySVG", parser: nil, completion: { (svgLayer) in
            svgLayer.resizeToFit(CGRect(x: 0, y: 0, width: 20, height: 20))
            svgLayer.frame.origin = CGPoint(x: 0, y: 15
            svgLayer.fillColor  = color.cgColor
        })
        svgView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
        svgView.backgroundColor = UIColor.clear
        self.myView1.addSubview(svgView)

svgView = UIView(SVGNamed: "mySVG_clone", parser: nil, completion: { (svgLayer) in
            svgLayer.resizeToFit(CGRect(x: 0, y: 0, width: 20, height: 20))
            svgLayer.frame.origin = CGPoint(x: 0, y: 15
            svgLayer.fillColor  = color.cgColor
        })
svgView.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
svgView.backgroundColor = UIColor.clear
self.myView2.addSubview(svgView)