UIBezierPath to NSData to Server to Android

≡放荡痞女 提交于 2019-12-10 00:48:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!