问题
currently I have a class that conforms to NSCoding containing a UIBezierPath and a UIColor.
required init(coder aDecoder: NSCoder) {
super.init()
self.lineColor = aDecoder.decodeObjectForKey("color") as! UIColor
self.bezierPath = aDecoder.decodeObjectForKey("bezier") as! UIBezierPath
}
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(lineColor, forKey: "color")
aCoder.encodeObject(bezierPath, forKey: "bezier")
}
I achieve this with NSKeyedArchiver
NSKeyedArchiver.archivedDataWithRootObject(path)
and save it on a server (parse.com) I can unarchive it with no problem with iOS. But how to be compatible with Android?
回答1:
You'd need to convert the paths and colours into some common format and export it in a common format. Something like SVG including the RGBA values. UIBezierPath
and keyed archiving are iOS specific items with private binary implementations - trying to work with them on Android will take you a long time and not be future proof.
回答2:
I'd agree with Wain. You can call self.bezierPath.CGPath to retrieve a CGPath, and then you can use the following answer to get it into SVG.
How to convert CGPath to SVG
Then you can send it along in a neutral format.
来源:https://stackoverflow.com/questions/30998142/uibezierpath-to-nsdata-to-server-to-android