【问题标题】:Geographical maps with SVGKIT带有 SVGKIT 的地理地图
【发布时间】:2012-12-18 08:12:12
【问题描述】:

我正在尝试将 SVGKit (https://github.com/SVGKit/SVGKit) 用于处理地理地图的 iOS 项目。

此时,我可以使用 CALayer 对象访问地图上的特定区域。这让我可以访问该区域周围的矩形。

这是我使用的代码:

CALayer *layer=[svgView.document layerWithIdentifier:@"myLayerID"];
[layer setBackgroundColor:[UIColor orangeColor].CGColor];

if( [layer isKindOfClass:[CAShapeLayer class]] )
{
    CAShapeLayer* shapeLayer = (CAShapeLayer*) layer;
    NSLog(@"That is good so far!");
    layer.mask=shapeLayer;
}

但我需要访问地图的精确区域;不仅是周围的矩形,为了突出它。 我读过我应该使用 CGPathRef 和掩码。

我该怎么做?

感谢任何提示。

【问题讨论】:

    标签: ios4 svg calayer cashapelayer


    【解决方案1】:

    找到 CALayer 后,将其转换为 CAShapeLayer(如果可以;如果您有正确的层,这应该可以正常工作)。

    if( [layer isKindOfClass:[CAShapeLayer class]] )
    {
       CAShapeLayer* shapeLayer = (CAShapeLayer*) layer;
    
       // Now you have access to lots more Apple methods
    }
    

    然后您可以更改线宽、填充颜色等 - 各种时髦的东西。

    还可以查看 CALayer.shadow* - Apple 提供的各种功能,这些功能将自动突出显示图层的可见部分。

    【讨论】:

    • 感谢您的回复。实际上是的,我可以将其转换为 CAShapeLayer。但是我仍然没有达到突出该区域的最终目标。我编辑了我的问题以反映我的所作所为。我认为我得到的 CAShapeLayer 已经有正确的路径可以用作适当的掩码。这是错的吗?我有点迷失在这里。我认为使用 SVGKit 会使事情变得相当简单,但显然情况并非如此,至少在开始时是这样。
    • 您需要阅读 Apple API 文档……您上面的代码毫无意义。您不能将图层用作自身的蒙版!
    猜你喜欢
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多