UPDATE滾動的MKMapView圓下方繪製的MKMapView
我需要畫一個圓到MKMapView
,一些地方我可以得到圓的半徑和它的中心座標。但是,我還希望該圓是MKMapView
的子視圖,以便地圖視圖可以在圓下面滾動,在地圖移動時更新其中心座標,並在地圖放大和縮小時更新其半徑。
有誰知道我可能能做到這一點?
這是問題的最初的措辭
我用下面的代碼畫出的圓到MKMapView
:
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.region = [MKCircle circleWithCenterCoordinate:self.locationManager.location.coordinate radius:kViewRegionDefaultDistance];
[self.mapView addOverlay:self.region];
}
- (MKOverlayPathRenderer *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
MKCircleRenderer *region = [[MKCircleRenderer alloc] initWithOverlay:overlay];
region.strokeColor = [UIColor blueColor];
region.fillColor = [[UIColor blueColor] colorWithAlphaComponent:0.4];
return region;
}
這工作,併產生在一個圓地圖視圖。但是,當我滾動地圖視圖時,圓圈隨之移動。 我希望圓圈保持靜止,並讓地圖視圖在圓圈下方滾動。
重要的是要注意,我需要獲取圓的中心座標和半徑以創建區域。出於這個原因,我不能簡單地在MKMapView上繪製一個UIView,因爲我無法獲得以UIView爲單位的半徑。
這爲添加和用於覆蓋除去MKCircle更穩定的溶液。感謝您發佈它。 – Carl