Ios 如何使用Swift在地图上填充外部覆盖圆
我正试图在地图上创建一个覆盖图,完全如本文中的图片所示:。我已阅读了这些说明,以实现目标C中的目标,并尽力将其转换为swift,如下所示:Ios 如何使用Swift在地图上填充外部覆盖圆,ios,swift,maps,Ios,Swift,Maps,我正试图在地图上创建一个覆盖图,完全如本文中的图片所示:。我已阅读了这些说明,以实现目标C中的目标,并尽力将其转换为swift,如下所示: override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext) { print("overlay") // Fill full map rect with some color.
override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext) {
print("overlay")
// Fill full map rect with some color.
let rect: CGRect = rectForMapRect(mapRect)
CGContextSaveGState(context)
CGContextAddRect(context, rect)
CGContextSetFillColorWithColor(context, UIColor.whiteColor().colorWithAlphaComponent(0.4).CGColor)
CGContextFillRect(context, rect)
CGContextRestoreGState(context)
// Clip rounded hole.
CGContextSaveGState(context)
CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetBlendMode(context, CGBlendMode.Clear)
CGContextFillEllipseInRect(context, rect)
CGContextRestoreGState(context)
// Draw circle
super.drawMapRect(mapRect, zoomScale:zoomScale, inContext:context)
}
我知道我不知道如何让这段代码作为覆盖运行。正如你可能知道的,我在这方面有点新手,但这是我第一次陷入如此困境,我无法从其他答案中找到答案 将视图作为子层添加到主视图的层不是解决方案吗?