Kyl*_*ott 3 core-graphics ios uibezierpath
UIBezierPath是否有任何可行/合理的方法来从远程 API传递必要的路径信息?我有兴趣在运行时下载形状信息。这是我的意思的梦想代码示例:
CGPath path = [APIClient downloadPathInfoForObject:clock];
UIBezierPath *bPath = [UIBezierPath bezierPathWithCGPath:path];
Run Code Online (Sandbox Code Playgroud)
如何从 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!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
869 次 |
| 最近记录: |