如何使用Swift

时间:2015-06-29 22:02:39

标签: ios swift maps

我正在尝试在地图上创建一个覆盖图,与此帖中的图片完全相同:How to fill outside overlay circle in iOS 7 on map。我已阅读这些说明以在Objective C中实现此目的,并尽力将其转换为swift,如下所示:

     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)
    }

我知道我不知道如何让这段代码作为叠加层运行。你可以告诉我这是一个新手,但这是我第一次如此困难,我不能从这里的其他答案中解决它!

0 个答案:

没有答案