Ios 从远程位置加载CGpath/UIBezierPath

Ios 从远程位置加载CGpath/UIBezierPath,ios,core-graphics,uibezierpath,Ios,Core Graphics,Uibezierpath,是否有任何可行/合理的方法从远程API传递UIBezierPath所需的路径信息?我对在运行时下载形状信息感兴趣。下面是我的意思的一个梦想代码示例: CGPath path = [APIClient downloadPathInfoForObject:clock]; UIBezierPath *bPath = [UIBezierPath bezierPathWithCGPath:path]; 如何从API发送路径信息,然后将其解包到CGPath 我可能最终会使用常规图像,但在整个应用程序中使用

是否有任何可行/合理的方法从远程API传递
UIBezierPath
所需的路径信息?我对在运行时下载形状信息感兴趣。下面是我的意思的一个梦想代码示例:

CGPath path = [APIClient downloadPathInfoForObject:clock];
UIBezierPath *bPath = [UIBezierPath bezierPathWithCGPath:path];
如何从API发送路径信息,然后将其解包到CGPath


我可能最终会使用常规图像,但在整个应用程序中使用CAShapeLayers会很酷。有什么想法吗?

UIBezierPath
支持
NSCoding
,因此您应该能够使用
NSKeyedArchiver
对其进行序列化,然后使用
NSKeyedUnarchiver
将其发送并反序列化到另一位置的另一个
UIBezierPath

示例

// Get a base64 encoded archive of the path
UIBezierPath *path = UIBezierPath.path;
NSData *pathData = [NSKeyedArchiver archivedDataWithRootObject:path];    
NSString *pathString = [pathData base64Encoding]; // Save it to the API

// ...... sometime in the future

NSString *pathString = [APIClient downloadPathForObject:clock]; // Get the string
NSData *pathData = [[NSData alloc] initWithBase64Encoding:pathString];
UIBezierPath *path = [NSKeyedUnarchiver pathData]; // Same path!

您可以使用SVG和一些类似的代码。

您可以使用PDF。PDF是在iOS上存储/检索矢量数据的本机格式。或者,如果这太过分了,并且您实际上只需要基本路径而没有任何属性,那么您可以使用自己的简单文件格式

可能像文本文件一样简单,有点像:

p 45.0 45.0
l 32.0 32.0
b 50.0 50.3 60 70 80 90.5
l 100.0 100.0
e

其中p是在给定坐标处开始路径的命令,l是在坐标处添加一条线,b是在最后一对坐标处结束的贝塞尔曲线,e是路径的终点。很容易解析。

谢谢,@zaph。这似乎是应该走的路。我编辑了你的答案,添加了一个对我来说确实有效的例子。