几天以来,我一直在努力解决问题,但没有取得良好的结果。我在MKMapView上有一个要点。我有UISlider,并且想要更改MKCircle的大小。大小已更改,但在调整大小时,该圆圈闪烁并闪烁。

这是我的代码:

@implementation ViewController {
    Annotation *_annotation;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _annotation = [[Annotation alloc] init];
    [_annotation setCoordinate: CLLocationCoordinate2DMake(0, 0)];
    [self.mapView addAnnotation:_annotation];
    [self.mapView setCenterCoordinate:_annotation.coordinate animated:YES];

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(_annotation.coordinate, 1000, 1000);
    [self.mapView setRegion:region];

    [self _addCircleOnCurrentLocationWithRadius:_slider.value];
}

- (IBAction)onSliderChanged:(UISlider *)sender {
    [self.mapView removeOverlays:self.mapView.overlays];
    [self _addCircleOnCurrentLocationWithRadius:sender.value];
}

- (void)_addCircleOnCurrentLocationWithRadius:(CGFloat)radius {
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:_annotation.coordinate radius:radius];
    [self.mapView addOverlay:circle level:MKOverlayLevelAboveRoads];
}

#pragma mark - MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Annotation"];
    return view;
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay {
    MKCircleView *view = [[MKCircleView alloc] initWithCircle:overlay];
    view.fillColor = [UIColor redColor];
    view.strokeColor = [UIColor blueColor];
    view.alpha = 0.3;
    return view;
}

@end

我试过了:
  • 删除旧的覆盖并添加新的
  • NSOperationQueue一起执行

  • 这是a screen recording how it looks like

    我认为这是可行的,Apple在提醒应用程序中做到了这一点。

    我也熟悉以下主题:
  • Smooth resizing of MKCircle
  • Moving MKCircle on MKMapview and dragging MKMapview
  • Smooth resizing of MKCircle

  • 先感谢您。

    编辑
    我做到了我将在类中添加一个答案,该类支持今天或明天调整大小。

    最佳答案

    我通过创建MKCircleView的子类并重写- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx方法来做到这一点。 TSCircleView class is shared on github here.

    关于ios - 在MKMapView上调整MKCircle的大小闪烁,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24766327/

    10-11 09:08