我尝试解决问题几天,但我没有取得好成绩。我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在Reminders app中做到了这一点。
此外,我熟悉以下主题:
提前谢谢。
修改 我做到了。我将在课程中添加一个答案,支持今天或明天的大小调整。
答案 0 :(得分:1)
我是通过创建MKCircleView的子类并覆盖- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx
方法来完成的。 TSCircleView class is shared on github here.