【发布时间】:2015-05-30 09:15:27
【问题描述】:
我是编码新手,我正在尝试实现类似提醒应用程序:
我已经关注另一个answer 来实现它并
这是我的代码:
在我的视图控制器中:
var circle = MKCircle(centerCoordinate: location.coordinate, radius: 100)
self.mapView.addOverlay(circle)
在我的 MKMapView 中:
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if overlay is MKCircle
{
render = MapFillRenderer(overlay: overlay)
return render
} else {
return nil
}
}
还有 MapFillRenderer(MKOverlayRenderer 的子类):
class MapFillRenderer: MKOverlayRenderer {
var colorIn: UIColor
var colorOut: UIColor
override func drawMapRect(mapRect: MKMapRect, zoomScale: MKZoomScale, inContext context: CGContext!) {
// Fill full map rect with some color.
var rect = self.rectForMapRect(mapRect)
CGContextSaveGState(context);
CGContextAddRect(context, rect);
CGContextSetFillColorWithColor(context, colorOut.CGColor)
CGContextFillRect(context, rect);
CGContextRestoreGState(context);
// Clip rounded hole.
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, colorIn.CGColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillEllipseInRect(context, self.rectForMapRect(self.overlay.boundingMapRect))
CGContextRestoreGState(context);
// Draw circle
super.drawMapRect(mapRect, zoomScale: zoomScale, inContext: context)
}
}
问题:
但是当用户移动地图时,我遇到了一个问题,主蒙版没有刷新,也没有填满整个地图区域。 值得注意的是,它会刷新,但只有当我足够缩小时。 当用户在不缩小地图的情况下移动地图时,如何强制刷新? 我试过了,但失败了:
func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) {
if render.overlay != nil {
render.setNeedsDisplay()
}
}
感谢您的任何想法,
这里是用户在不缩放的情况下移动地图时的结果图片:
【问题讨论】:
-
注意:Reminders Apple App,当您为某个位置添加提醒时,有同样的错误
标签: ios swift mapkit mkoverlay