是否有任何可行/合理的方式从远程API为UIBezierPath传递必要的路径信息?我对在运行时下载形状信息感兴趣。这是一个梦代码的例子,我的意思是:
CGPath path = [APIClient downloadPathInfoForObject:clock];
UIBezierPath *bPath = [UIBezierPath bezierPathWithCGPath:path];您如何从API中发送路径信息,然后将其解压缩到CGPath?
我可能最终会使用常规图像,但在整个应用程序中使用CAShapeLayers是很酷的。有什么想法吗?
发布于 2014-07-17 17:43:03
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!发布于 2014-07-17 17:43:21
您可以使用SVG和一些代码(如这个图书馆 )。
发布于 2014-07-17 18:08:52
你可以用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是在最后一对坐标处结束的bezier曲线,e结束该路径。很容易解析。
https://stackoverflow.com/questions/24810066
复制相似问题