CGPathRef encoding

主宰稳场 提交于 2019-12-06 08:44:45

问题


Is it possible to encode CGPathRef variables? I mean is there an encodeObject:forKey like method for CGPathRef variables?


回答1:


yes, there is - I have done this: https://github.com/mro/MROGeometry/blob/master/NSCoder_MROCGPath.m




回答2:


CGPaths are objects, but I don't think you can encode them—at least, if you can, it's not documented. You'll need to generate a saveable representation of the path yourself, and encode that, and then, when you decode that representation, reincarnate the path from it yourself.




回答3:


This header on Github has two utility strings to interchange CGPaths with NSStrings:

+(nullable NSString*) svgPathFromCGPath:(CGPathRef)aPath;
+(nullable CGPathRef) newCGPathFromSVGPath:(NSString*)anSVGPath whileApplyingTransform:(CGAffineTransform)aTransform;

You can use those strings with NSCoders to store things away. Be warned that anytime you convert between paths and strings you might lose significant digits because of the conversion.

I wrote these routines and they are under MIT license.



来源:https://stackoverflow.com/questions/1429426/cgpathref-encoding

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